简体   繁体   中英

how can i get MC in stage function?

i create three circles. if a circle is dragged to right side of the stage, it becomes invisible and vice versa. when MOUSE_UP is invoked, it must stay in its last position.

so in the appear() function how can i assign the selected circle to current_mc?

function createCircles(evt:Event):void
{    
    for(i=0; i<3; i++)
    {
    var figure:Sprite=new Sprite();            
    figure.circle.x=10;
    figure.circle.y=i*figure.circle.height*1.02;
    figure.circle.buttonMode=true;
    figure.circle.addEventListener(MouseEvent.MOUSE_DOWN,downFNC);
    addChild(figure.circle);
    }
}
function downFNK(evt:MouseEvent):void{
    current_mc=MovieClip(evt.target);
    current_mc.x=mouseX;
    current_mc.y=mouseY;
    stage.addEventListener(Event.ENTER_FRAME,appear); 
}

function appear (evt:Event):void
{
    current_mc=???
    current_mc.x=mouseX;
    current_mc.y=mouseY;
    if(mouseX > stage.width/2)
        current_mc.visible=false;              
    else
        current_mc.visible=true;
    stage.addEventListener(MouseEvent.MOUSE_UP, upFNC);
}
function upFNC(evt:MouseEvent):void
{
    stage.removeEventListener(Event.ENTER_FRAME, appear);
}

I am a little confused. You assign current_mc in your downFNK, so then in your appear function it should still be assigned.

Also, instead of listening for Event.ENTER_FRAME, you should change it to listen for MouseEvent.MOUSE_MOVE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM