简体   繁体   中英

how to add more animations to the stage when clicking a button in flash

i want to add more fish to my flash fish tank by clicking a button..i tried this code but my fish animation is not getting animated after i click the button..and i'm using action script 3 ..

    function fl_MouseClickHandler_2(event:MouseEvent):void
{
    // Start your custom code
    // This example code displays the words "Mouse clicked" in the Output panel.
    trace("Mouse clicked");

    addChild(f3);
    addChild(eat)   ;
    addChild(hello) ;
    addChild(f2)    ;
    addChild(f1)    ;
    // End your custom code



}

f1,f2,f3,eat,hello are my fishes..

This is my infinite scrolling code..all the fishes are in separate layers ..so for each layer i have put this code..by just changing the instance name and the function.

    f3.addEventListener(Event.ENTER_FRAME, fnewm);
function fnewm(evt:Event)
{   
    if(f3.x + f3.width <= 0) //movieclip is outside left side of stage
    {
        //set new position
        f3.x = stage.stageWidth;
    }
    else
        f3.x -= 5;

}

As you "Mouse clicked" message don't show in console I can assume either of two options:

  1. Somehow you didn't setup event listener to the button;
  2. Your button is not on the top layer so the click is not registered because it is hidden by something.

I can't tell you exactly, but you can try manually set button's depth. More info on how to do it can be found here

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