ForumsProgramming Forum(As3) Can't change name of a timeline placed object?

3 2638
mightybob
offline
mightybob
364 posts
1,050

I am getting this weird error, in as2 I could change the name of timeline objects all i wanted thru code... No problemo!
But in as3 its not letting me do this...

(I'm getting this error: "Cannot change name of timeline placed objects")

I'm trying to add objects to an array but I need each object to need a separate name, but As3 isn't letting me change the name...

this.name = ("tile" + MovieClip(root).tiles.length);
MovieClip(root).tiles.push(this);

Is there a work around for this?

  • 3 Replies
weirdlike
online
weirdlike
1,298 posts
27,225

timeline placed objects are named with instance names, that is being declared as it is loaded. So it will not allow you to change the name (it is basically written in stone).

The best practice is to addChild then give the name as you added the MovieClip

How can you do this with timeline placed objects???

pretty easy... you take the frame that the level is on convert to MovieClip (yes the whole level) then clear the frame. Now I like to think of this as a mini-map. Then you can use code to add the children by using the for loop. Once the loop is done, the whole level will be setup and you can then run the enter frame loop to take control of the objects.

Would you like me to make a demo of what I am talking about?

mightybob
offline
mightybob
364 posts
1,050

No thanks, I think I get what you're talking about.

You're saying use a bunch of empty movie clips to show where i'm going to place the things with addChild() and then I could do? :

addChild(coin)
coin.x = coinHolder.x;
coin.y = coinHolder.y;

The thing that confuses me here is that in As2 they let you change names on runtime of timeline placed objects, but in As3 adobe decided to remove that? That seems to only be limiting control over what people can make...
Oh well.

Thanks for your help!

weirdlike
online
weirdlike
1,298 posts
27,225

what I like to do is this, and remember copy past wont work due to the less than symbol

var map:Object;

if(level1)
{
var l1:level1class = new level1class;
map = l1;
}
else if(level2)
{
var l2:level2class = new level2class;
map = l2;
}

for (var i:int=0; i &lt map.numChildren; i++)
{
var object = map.getChildAt(i);

if (object is enemy1MC)
{
var e1:enemy1 = new enemy1();
e1.x = object.x;
e1.y = object.y;
enemyArray.push(e1);
level.addChild(e1);
e1.name = "e1";
(e1.addEventListener)
}
}

Showing 1-3 of 3