dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Flash code help with addEventListener actionscript 2.0

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    9

    Flash code help with addEventListener actionscript 2.0

    Alright here's the setup.

    actionscript 2.0

    I have an animated mirror with sound. (Mmirror)

    There is a button to toggle the mirror visible or not. (mirrorBTN)
    The button is inside a menu movieclip. (BelleMenuItems)

    The animation inside the mirror movieclip starts on frame 2. frame 1 has a stop.


    Here's the problem.

    (this was after I heard the sound playing with the mirror invisible.)
    when you toggle the movie visible its fine, I set it to gotoAndPlay frame 2, and looping back to 2. with a stop on 1. but when you toggle the movie invisible, the sound still plays, because its technically still playing the animation movieclip you just cant see it.

    I'm trying to add an event listener that knows when the movie clip is visible and invisible, and will tell it to go to the correct frame to start or stop the animation.

    It wouldn't be a problem if there was no sound, but I think the sound enhances the animation.

    here's the code i pulled out of the flash help to modify:

    Code:
    function eventResponse(eventObject:EventType):void
    {
        // Actions performed in response to the event go here.
    }
    
    eventTarget.addEventListener(EventType.EVENT_NAME, eventResponse);
    I dont really understand what all of these things mean, as i'm a self taught actionscriptor, still learning.

    Here's what I've modified. It may be completely wrong....I haven't tried it because I know it wont work since I haven't changed all the variables to what they should be. I just don't know what they should be.

    Code:
    // mirror animation start code
    function ManimON(eventObject:_visible=true):void
    {
        _root.Mmirror.gotoAndPlay(2);
    }
    
    _root.BelleMenuItems.mirrorBTN.addEventListener(_visible=true.EVENT_NAME, ManimON);
    
    // mirror animation stop code
    function ManimOFF(eventObject:_visible=false):void
    {
        _root.Mmirror.gotoAndPlay(1);
    }
    
    _root.BelleMenuItems.mirrorBTN.addEventListener(_visible=false.EVENT_NAME, ManimOFF);
    This is the only solution I could think of, but if there is an easier one, please share.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    // Note: in the Mmirror movie clip, set sound Sync to 'Stream', not 'Event'.
    
    function ManimONOFF(e:Event):void {
    	var mc:MovieClip=e.currentTarget.parent.parent.Mmirror;
    	mc.gotoAndStop(1);
    	mc.visible=! mc.visible;
    }
    
    BelleMenuItems.mirrorBTN.addEventListener(MouseEvent.MOUSE_DOWN, ManimONOFF);
    
    Mmirror.addEventListener(MouseEvent.MOUSE_DOWN, Manim);
    function Manim(e:Event):void {
    	e.currentTarget.gotoAndPlay(2);
    }

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    so do I put that code on the button or on the main actions layer?


    the button already has

    Code:
    on (release) {
    _root.Mmirror._visible=!_root.Mmirror._visible;
    }
    or something like that... I am not on that computer right now.

  4. #4
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    Wait I dont need this code right if the button already turns the mc on?
    you wont be clicking the mirror at all, just the button, and i only want the animation to stop when the mirror is invisible. because there are other objects that appear that make the mirror dissappear.

    Code:
    Mmirror.addEventListener(MouseEvent.MOUSE_DOWN, Manim);
    function Manim(e:Event):void {
    	e.currentTarget.gotoAndPlay(2);
    Code:
    on (release) {
    _root.Mmirror._visible=!_root.Mmirror._visible;
    _root.Mmirror.gotoAndPlay(2);
    }

  5. #5
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    Your code didn't work. I'm just going to take the sound out. I might call on it later when the movie clip hits a named frame or something. I dunno, thanks anyway, but I'm going without sound for now.

    I appreciate you responding though. you helped me out last time.

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