How to maintain a movieclip's color between frames?

流过昼夜 提交于 2019-12-20 06:27:48

问题


My app has 2 frames; in frame 1 there are 5 MC and on a DOUBLE_CLICK event the target's color change and go to the next frame 2.
In frame 2 I have a button to return to frame 1.

How can i maintain the MC color when I return to frame 1?

public class test extends MovieClip
{
    public function test()
    {
        var myMCTable:Array = [myMC1, myMC2, myMC3, myMC4, myMC5];
        for (var i:uint = 0; i < myMCTable.length; i++)
        {
            myMCTable[i].doubleClickEnabled = true;
            myMCTable[i].addEventListener(MouseEvent.DOUBLE_CLICK, changeColor);
        }
    }

    private function changeColor(e:MouseEvent) : void
    {
        var newColorTransform:ColorTransform = (e.target).transform.colorTransform;
        newColorTransform.color = Math.random() * 0xFFFFFF;
        (e.target).transform.colorTransform = newColorTransform;
        nextFrame();
        goBack_btn.addEventListener(MouseEvent.CLICK, goBack);
    }

    private function goBack(e:MouseEvent) : void
    {
        prevFrame();
    }
}

回答1:


The simplest way would be to have three frames, create your MCs on frame 1 and switch between frame 2 and 3.

You could also store the color information in an object.

_color[e.target.id] = newColorTransform.color;

And then retrieve it and apply it. But there again you will need to have the initialization of your data object on a previous, third frame. If you don't it will be reinitialized and you will lose your colors.




回答2:


If you make a class for the movieclips (you have 5 I believe) that they all share. Create a class property called myColor, then update each individual movieclip object's "myColor" property whenever it is double-clicked and the color changes, you can make the "goBack()" method re-apply each movieclip's color from its own property.

Does this make sense?



来源:https://stackoverflow.com/questions/8242838/how-to-maintain-a-movieclips-color-between-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!