Skip to main content
Inspiring
July 17, 2014
Answered

AS3 - Multiple instances

  • July 17, 2014
  • 1 reply
  • 1656 views

I have created 4 types of MovieClips objects.

How can I create (name) intances for every type of these objects to be shown on the scene? (every type can appear more than twice)

This topic has been closed for replies.
Correct answer Ned Murphy

First you need to designate the object in the library as an item that can be loaded dynamically.

Right click on it in the library and select Linkage from the menu that appears. In the interface that appears, select Export for Actionscript. A Class name will automatically be assigned, which you can change as you like (lets just say you name it MyObject). This is the name you will use to call in the item from the library.

When you click OK to close that interface, it may come up with an indication saying it can't find the class so it will create one at complie time... click OK there too.  You're done preparing the object in the library.

To add the item to the stage, treat it like any other new object instance:

var newObject:MyObject = new MyObject();
newObject.x = .... etc...
this.addChild(newObject);

1 reply

Ned Murphy
Legend
July 17, 2014

Your question is not clear to me.

You can create multiple instances either by dragging them from the library and assigning each an instance name, or you can assign each of the four a unique class identity and dynamically add mutliples of them one at a time.

A MovieClip-based object has a name property that you can assign a value (String) to.  In the case of a manually added object the name will be the same as the instance name.

gibsyAuthor
Inspiring
July 17, 2014

I want to add them dinamically in a random number to an array and I need to know exactly where is everyone. It can appear 1 time, 2 times, ... 5 times or 0 times.

"or you can assign each of the four a unique class identity and dynamically add mutliples of them one at a time."

How can I do that?

Ned Murphy
Ned MurphyCorrect answer
Legend
July 17, 2014

First you need to designate the object in the library as an item that can be loaded dynamically.

Right click on it in the library and select Linkage from the menu that appears. In the interface that appears, select Export for Actionscript. A Class name will automatically be assigned, which you can change as you like (lets just say you name it MyObject). This is the name you will use to call in the item from the library.

When you click OK to close that interface, it may come up with an indication saying it can't find the class so it will create one at complie time... click OK there too.  You're done preparing the object in the library.

To add the item to the stage, treat it like any other new object instance:

var newObject:MyObject = new MyObject();
newObject.x = .... etc...
this.addChild(newObject);