change movieclip instance name in runtime

510 views Asked by At

I'm trying change movieclip instance name in runtime, with name property but I have error

Error #2078: The name property of a Timeline-placed object cannot be modified. 

I tried to create new movieclip in runtime asign my old movie clip and change name property but I have same error...

and is any way to change instance name of movieClip in runtime?

1

There are 1 answers

0
Sergio On

So far the only workaround I've found is to use an array:

import flash.display.MovieClip;
import flash.geom.ColorTransform;

var t:Boolean; // for toggle function
var square: Array = new Array();
var changeColor: ColorTransform = new ColorTransform();

for (var i: int = 0; i < 5; ++i) {
    var rect: MovieClip = new MovieClip();
    rect.graphics.beginFill(0xaaaaaa);
    rect.graphics.drawRect(10, 10, 50, 50)
    addChild(rect);
    rect.x = 75 * (i + 1);
    rect.y = 100;

    square.push(rect)

}

// This toggles the middle square up and down, and gray to red.
square[2].addEventListener(MouseEvent.CLICK, toggle);

function toggle(event: MouseEvent): void {

    if (!t) {

        changeColor.color = 0xff00000;
        square[2].transform.colorTransform = changeColor;

        square[2].y = 50;

    } else {

        changeColor.color = 0xaaaaaa;
        square[2].transform.colorTransform = changeColor;

        square[2].y = 100;
    }

    t=!t;
}