Skip to main content
Inspiring
March 15, 2008
Question

Newbie - How do I instantaneity an object from the current Project Library?

  • March 15, 2008
  • 1 reply
  • 648 views
I created an object and placed it into the library. How do I create an instance of it with AS3.
Can someone point me to an example?

Thank You!

This topic has been closed for replies.

1 reply

Inspiring
March 16, 2008
notoriousvictor,

> I created an object and placed it into the library. How do I
> create an instance of it with AS3.

You'll need to associate that Library asset with a linkage class.
Right-click/Command-click and choose Linkage, then select "Export for
ActionScript" to enable the class field. Flash will automatically populate
the field with a name that closely matches the asset's library name. If you
like, you may change this class name as you please. If the asset is a movie
clip, you'll see that the base class is MovieClip; if it's a bitmap, you'll
see that the base class is BitmapData, and so on.

The way to instantiate the asset depends on the sort of class it is.
For movie clips, it's as easy as:

var myClip:YourClassName = new YourClassName();

... where "YourClassName," of course, matches whatever linkage class name
you gave the asset in the Library. Because it extends MovieClip -- in this
example -- your instance supports all the features of that class, such as x
and y properties:

myClip.x = 400;
myClip.y = 240;

... and then, because this is a visual asset, you have to add it to the
display list:

addChild(myClip);

... and you're done. If it's an audio file, you would instantiate it the
same as any Sound instance. If it's a bitmap, you would have to associate
it with a Bitmap instance. But this might just be a font or some other
asset, so it all depends.

What have you got? :)


David Stiller
Co-author, Foundation Flash CS3 for Designers
http://tinyurl.com/2k29mj
"Luck is the residue of good design."


Inspiring
March 16, 2008
Perfect, exactly what I needed.

Thank you for the detailed explaination.
Participating Frequently
March 28, 2008
ive been doing this method for a while but now am getting a strange error::

public var button:Array = new Array();
button = new btnButton;

error:
1180: Call to a possibly undefined method btnButton.


I have created btnButton movie clip and the btnButton Class and linked them correctly and I am still getting the same error is there anything else that I should try.