A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [AS3] How to stop playing movie clip after some time

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    1

    [AS3] How to stop playing movie clip after some time

    I made a game in adobe flash cs6 [AS3] and i am having a problem…

    I just made a shooting game, in which , there is a turret , which faces towards the mouse..

    The code for this if someone needs :-


    Code:
    function moveturret (e:Event)
    
    {
    aim.x = mouseX
    aim.y = mouseY
    var differenceX = mouseX – turret.x;
    var differenceY = mouseY – turret.y;
    var radianToDegrees = (Math.PI/180);
    turret.rotation = Math.atan2(differenceY, differenceX)/radianToDegrees;
    }

    now, i made the thing that, whereever we click, a explosion appears.Every thing that touches the explosion will disapear.
    So, the problem is that, the explosion does not disappear!!
    Please help me with it….
    The whole code is like this:-



    Code:
    import flash.events.Event;
    import fl.motion.MotionEvent;
    
    addEventListener (Event.ENTER_FRAME,moveturret);
    Mouse.hide();
    var firegun:boom22 = new boom22();
    
    function moveturret (e:Event)
    
    {
    aim.x = mouseX
    aim.y = mouseY
    var differenceX = mouseX – turret.x;
    var differenceY = mouseY – turret.y;
    var radianToDegrees = (Math.PI/180);
    turret.rotation = Math.atan2(differenceY, differenceX)/radianToDegrees;
    }
    
    stage.addEventListener(MouseEvent.CLICK,fire);
    
    function fire (e:MouseEvent)
    
    {
    firegun.x = mouseX
    firegun.y = mouseY
    addChild(firegun);
    }
    firegun.addEventListener(Event.ENTER_FRAME, removeSelfWhenDone, false, 0, true);
    
    // on every frame tick, check if last frame is reached, if so, remove it from it’s parent (which would be the stage)
    function removeSelfWhenDone(inputEvent:Event):void {
    var clip:MovieClip = (MovieClip) (inputEvent.target);
    if(clip.currentFrame == clip.totalFrames){
    // also remove the event listener (as it gets added again later)
    clip.parent.removeChild(clip);
    clip.removeEventListner(Event.ENTER_FRAME, removeSelfWhenDone, false, 0, true);
    
    }
    }
    please help!!

  2. #2
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    You can try to debug things by using trace() actions. I would start by tracing the framecounts to make sure it's acting as you expect.

    For instance:

    Code:
    trace("MC.name: " + clip.name + " , currentFrame: " + clip.currentFrame + " , totalFrames: " + clip.totalFrames);
    I have no idea what firegun is, is that the explosion? Try a trace near the "removeChild" code to check if that stuff is even called. You're not getting any errors?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center