Yaniv
Yaniv

Reputation: 7

AS3 instantiate an object without creating a class file

I have quite a basic question that has been bugging me for a while.

How do I import a few movie clips from the library to the stage, they don't need any behavior just to be spawned dynamically. Their behavior may be set from the main class.

For example I want to create a few vector elements for a background and instantiate them randomly.

Thank you, Yaniv.

Upvotes: 0

Views: 187

Answers (2)

Sr.Richie
Sr.Richie

Reputation: 5740

Draw your stuff in Flash, then convert it to Symbol > MovieClip.

It the dialog panel, check "Export for Actionscript" and give it as Class Name the name you want for it , for example MyBackground. Let the base class flash.display.MovieClip. Flash will prompt you with a warning "A Definition for the base class could not be found.....", and that's ok, it is just warning you that the class for it it's actually missing, and one will be autogenerated.

Later in your code you can instantiate it your class by simply:

  var back:MyBackground = new MyBackground();

Upvotes: 0

Azzy Elvul
Azzy Elvul

Reputation: 1438

You can use new MovieClip() and than add it into stage or if you have a movie clip in your library you can give it a linkage name and than instantiate it with new

Upvotes: 1

Related Questions