Skip to main content
Inspiring
February 20, 2008
Question

var on a clip

  • February 20, 2008
  • 2 replies
  • 261 views
Hi,

I am trying to set a variable on a new sprite attatched to the main
timeline (addchild). But I am too stupid I tried several ways. Last one
looks like this


for (n=0;n<50;n++){
this["newClip" + n] = new Sprite();
newClip = this["newClip" + n]
...
newClip.name = "clip" + n + "_mc";
var clip = this.addChild(newClip);

// how do I set a simple variable on it?
clip.idx = n;


..


TIA!
This topic has been closed for replies.

2 replies

Inspiring
February 21, 2008
Nixy wrote:
> Try it
> for(var n:int = 0; n < 50; n++)
> {
> var newClip:MovieClip = new MovieClip();
> newClip.name = "clip" + n + "_mc";
> newClip.idx = n;
> addChild(newClip);
>
> trace(newClip.idx)
> }
>
> It seems that Sprite is not like MovieClip. MovieClip you can add dynamicly
> properties. I think that Sprite can't.

Ah I see. I thought it would turn like a movieclip after addChild
command. Of cause it won't.

> You're better to set all var type. I know that it take time, but you'll same
> it later when you'll try to debug APP. There is many reason to set all var
> type, and that is why AS2 implement it.

Would I set the var type of 'idx'? I tried to use the var command but
then I get compiler error 1078.

var clip = this.addChild(newClip);

clip.idx = n;
// these won't work, shouldn't I set the type here?
clip.origX:int = clip.x
var clip.origY:int = clip.y
Inspiring
February 21, 2008
Try it
for(var n:int = 0; n < 50; n++)
{
var newClip:MovieClip = new MovieClip();
newClip.name = "clip" + n + "_mc";
newClip.idx = n;
addChild(newClip);

trace(newClip.idx)
}

It seems that Sprite is not like MovieClip. MovieClip you can add dynamicly properties. I think that Sprite can't.

You're better to set all var type. I know that it take time, but you'll same it later when you'll try to debug APP. There is many reason to set all var type, and that is why AS2 implement it.

That was just a suggestion ;-)