The Actionscript 2 File
Calling the script from the movie
Now we want to see what how our script affects the movie. To see that, we have to call the class function. Designwise, in our movie we make a movieclip, which we name "buttonClip" and inside there is the text you saw and the 3 buttons. To bring these buttons to life we first import the new class using the import method. So create an actions frame on the main timeline of the movie. We use import because we are lazy and don´t want to write the whole path for the function for every button instance. Next we create instances of the "uButton1" class for each button we have. This is very similar to creating any new object as you know it from AS1. We put the word "new" in front of the class name. We now add the parameters and here we have to be careful as well. Strings are placed within quotations but other parameters not. If we put the button parameter in quotations we will actually be in trouble.
//this imports the script and the whole path has to be specified here //but not later any more. import scripts.uButton1; //we create var of the uButton1 class. Parameters as strings need quotations but //not the other parameters. buttonClip.button1 specifies the path where the button is located. var myButton_1:uButton1 = new uButton1("http://www.flashkit.com","_blank",buttonClip.button1,0xFF8429,0xFF0000); var myButton_2:uButton1 = new uButton1("http://www.flashkit.com/board/forumdisplay.php?s=e8257289d3a4bcdac5a2939f5a535463&forumid=61","_blank",buttonClip.button2,0x31ADA5,0xFF0000); var myButton_3:uButton1 = new uButton1("http://www.flashkit.com/board/forumdisplay.php?s=086abae7b05a376b83a624e3616390ae&daysprune=20&forumid=30","_blank",buttonClip.button3,0xDE5AAD,0xFF0000);And that´s it for today. I hope to see more tutorials about AS2 in the future so I can learn more. Have fun.
|» Level Intermediate|
Rating: 4.89 Votes: 72
|The author is a basic scientist working in cancer research.|
|Download the files used in this tutorial.|
|Download (25 kb)|
|More help? Search our boards for quick answers!|