Copy link to clipboard
Copied
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)
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Thanks.
I've done that:
var arr: Sprite = new Sprite();
var i: int;
for (i = 0;i <= 5; i++)
{
var newObject:MyObject = new MyObject();
newObject.x = 20 * i;
newObject.type = i;
arr.addChild(newObject);
}
stage.addChild(arr);
Now how can I see what position is type 3 for example?
Copy link to clipboard
Copied
While I get the feeling you still are not making your question clear, if those are the only objects being added to the array then you could use the value of i to target the index...
trace(arr[3].x);
If there are more objects being added to the array from elsewhere then you can loop thru the array and test the type value of each object to see if it equals 3 and if it does, check its position.
If there are multiple objects that could have a type value of 3 then you might be better off using the name property and assign names to identify each object uniquely.
Copy link to clipboard
Copied
Ok. This was what I was looking for:
arr[3].x
Thanks.
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
Dear Ned,
i have the same question, i have created a movie clip (Symbole1) and gave it the name _clicp1 in the instance name, and i drag it / copy paste as Symbole1_copy and i wanted to give it an instance name clip2 from the property panel, but i was surprised that the symbole1 also has updated to the new name clip2 and so both of them now have hte same name.. i tried to rename the first one back to clip1, and i found out that symbole2 has now clip1 as name instead of clip2.. how can we rename each one on its own.. why they are related on the instance name ?