attachMovie in Actionscript 3.0
You might have been wondering where attachMovie is gone in Actionscript 3.0, well no need to look for it because it's gone. In Actionscript 3.0 you will have to use another way to attachMovie clips on the stage at runtime, I am going to tell you all about it in that little tutorial.
Tutorial The default way
When you create a movie clip in an AS3 Flash file and select "export for actionscript you will notice that the Class and Base class are automatically filled up (see picture below), what does that mean in the AS3 world?
Flash automatically fills the Class name field with the name you gave to your movie clip, square in our case. Also since it is a movie clip that we are creating it automatically fills the Base class field with flash.display.MovieClip.
You don't need to worry about the Base class, that means that your movie clip is going to inherit of all the properties and methods assigned to the MovieClip class. In AS2.0 this was happening in the background but you just did not know about it.
More importantly you can also see that the class square has automatically been assigned to the movie clip, this is an important bit, it means that the compiler will be automatically looking for square.as (a physical class that you actually created) in the directory where your Flash file resides, if it can't find it it will create a default one for you. You don't need to create a square class if you have nothing to put in it.
Ok, our movie clip is now sitting in the library, we now need to create the code that will attach it on the stage, this is what we are doing below:
var mySquare:square = new square(); |
That's it if you run your file you will now see that your movie clip is attached to the the top left corner of the stage.
Create your own class
If you want to create a little class for your square, it is easy, got in FILE > NEW and in the window select ACTIONSCRIPT FILE
Now you can create your class, a very simple square class could be like the one below:
package { import flash.display.MovieClip; public class square extends MovieCp{ |
Hopefully this little tutorial will be helpful for you :)
0 comments:
Post a Comment