In this tutorial i hope to show you how you can setup the use of color and Actionscript.
Its not a very big tutorial, but it might be useful for some of you out there.
Lets create some color
First lets create a new Flash file, 300x300 with a black background.
So open Flash, choose file > new > Flash Document and create it by pressing "ok".
Then press CTRL+j of choose modify > document to open up your document settings.
Thats where you can set its height, width, background color and some other things.
Leave the framerate at the default because its not important for this example.
I used Flash 8 but any Flash version above Flash 5 will do.
I didnt use strong datatyping like you can use in FlashMX2004 and Flash 8 only.
In other words this code will also work in Flash MX.
Now lets draw a square that has a 100 pixels width and 100 pixels height. After you created it double click it
to make sure the whole square is selected. Then press F8 to open the "convert to symbol" menu. In this new menu
just enter "square" as a name and you can leave the rest of the setting at default and press ok.
After you pressed ok, the square you drew was converted into a movieclip. Now go to the square's properties box to
set an instance name. Because you just created it its probably still selected, just look at the bottom of the Flash interface in
the properties box and look where it says "instance name". If you found it, call it "square".
Now create a new layer by pressing that little + sign in the menu, double click it to rename it to "code".
Then select the first frame on that layer and press F9 to open the Actionscript code editor.
Place this code there to make the square red when you run the file.
var myColor = new Color("square");
myColor.setRGB(0xff0000);
In the little bit of code above i first created a new instance of the Color class which gives us the ability to use all the
functions that are in that class. One of those functions is setRGB() which is what we use on the second line to make the square clip red.
Lets create some random color
If you want to have a bit of random colors you could even do this.
(run the Flash file a few times to see the colors change everytime you run it)
var myColor = new Color("square");
myColor.setRGB(random(255255255));
Lets expand it a little bit
For the fun of it lets trigger it on an onPress event. What that means is lets just give it a
random color when you press on the square. Add this code to your file.
var myColor = new Color("square");
square.onPress = function(){
myColor.setRGB(random(255255255));
}
live preview
Conclusion
I hope you enjoyed this small Flash Actionscript tutorial and that it could show you how to set a color onto an object with Actionscript.
If you have any questions please don't be shy
and post a message in the forum.
Comments
14 comment(s) found in 3 pages
viewing comment(s): 1 - 6
page: 1
1 | 2 | 3 |
29-10-07:Nichu
dats cool..........
04-08-07:guest
shauna
22-07-07:kochu
Really nice!
01-05-07:guest
4utrt dfkljkl fklghjgl hkg; s
21-04-07:guest
cool
17-04-07:IM A GUEST LAQUESHIA
THIS IS A GREAT GLITTER SITE!!!!!!!
- Press here to view all available smilies!