PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
pausing an event listener
A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: pausing an event listener

  1. #1
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    pausing an event listener

    i have a rollover function that sets alpha values, and i also have a click function that sets the alpha even higher on click. I also have a roll out function to return it to normal when roll out. The thing is i want it to hold the high alpha value on click because that is the web page is selected. It works, but the second i rool out or roll over, it sets the value back.

    What should i do?

    Actionscript Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    designClip.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage);

    function fl_ClickToGoToWebPage(event:MouseEvent):void
    {
        //navigateToURL(new URLRequest("http://www.google.com"), "_blank");
    }

    designClip.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

    function fl_MouseOverHandler(event:MouseEvent):void
    {
        var myTweenAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .4, 2, true);
    }

    designClip.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

    function fl_MouseOutHandler(event:MouseEvent):void
    {
        var myTweenAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .2, 2, true);
    }

    designClip.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

    function fl_MouseClickHandler(event:MouseEvent):void
    {
       
        var myTweenBigAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .8, 1, true);
        var myTweenSize:Tween = new Tween(designClip.yellow, "height", Strong.easeOut, designClip.yellow.height, 210, 3, true);
       
        //Other Clips Shrink
        var myTweenHomeSize:Tween = new Tween(Object(root).home.homeClip.orange, "height", Strong.easeOut, Object(root).home.homeClip.orange.height, 177, 3, true);
        var myTweenPhotoSize:Tween = new Tween(Object(root).photography.photoClip.white, "height", Strong.easeOut, Object(root).photography.photoClip.white.height, 177, 3, true);
        var myTweenMusicSize:Tween = new Tween(Object(root).music.musicClip.green, "height", Strong.easeOut, Object(root).music.musicClip.green.height, 177, 3, true);
        var myTweenAboutSize:Tween = new Tween(Object(root).about.aboutClip.blue, "height", Strong.easeOut, Object(root).about.aboutClip.blue.height, 177, 3, true);
       
        //all other buttons alpha to 20%
        var myTweenHomeAlpha:Tween = new Tween(Object(root).home.homeClip, "alpha", Strong.easeOut, Object(root).home.homeClip.alpha, .2, 2, true);
        var myTweenAPhotoAlpha:Tween = new Tween(Object(root).photography.photoClip, "alpha", Strong.easeOut, Object(root).photography.photoClip.alpha, .2, 2, true);
        var myTweenAMusicAlpha:Tween = new Tween(Object(root).music.musicClip, "alpha", Strong.easeOut, Object(root).music.musicClip.alpha, .2, 2, true);
        var myTweenAAboutAlpha:Tween = new Tween(Object(root).about.aboutClip, "alpha", Strong.easeOut, Object(root).about.aboutClip.alpha, .2, 2, true);
       
       
        function fl_ClickToGoToWebPage(event:MouseEvent):void
        {
        //navigateToURL(new URLRequest("http://www.google.com"), "_blank");
        }
    }

  2. #2
    Junior Member
    Join Date
    Jun 2010
    Posts
    16
    Basicly, you need to keep in memory which buttons is the current clicked button
    Actionscript Code:
    var current_button:MovieClip;
    in your mouse out, add these lines

    Actionscript Code:
    if(current_button != e.currentTarget)
    //do your mouse out actions, so it wont roll out if the button you just clicked is the current button

    In your mouse click event function, you need to add some code as well
    Actionscript Code:
    //if not null, it means a button has already been clicked so we want this old active button to return to normal
    if(current_button != null)
    {
    //current_buttontween your current button to normal
    //then we associate the new clicked button into the variable
    current_button = e.currentTarget as MovieClip;
    }

    //then we tween the current button to the high alpha

    I hope it helps you.

  3. #3
    Junior Member
    Join Date
    Apr 2006
    Posts
    28
    ok that kind of makes sense.
    ill try it and get back to you.

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    Why do you use CLICK event in this case?
    I think you'd better use MouseEvent.MOUSE_DOWN and MouseEvent.MOUSE_UP instead. This will simplify your work a lot

  5. #5
    Junior Member
    Join Date
    Apr 2006
    Posts
    28
    Quote Originally Posted by caseyryan View Post
    Why do you use CLICK event in this case?
    I think you'd better use MouseEvent.MOUSE_DOWN and MouseEvent.MOUSE_UP instead. This will simplify your work a lot
    I don't understand how that would simplify my work, could you please explain further?

  6. #6
    Junior Member
    Join Date
    Apr 2006
    Posts
    28
    ok here is what i have:

    Actionscript Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    var current_button:MovieClip;

    designClip.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage);

    function fl_ClickToGoToWebPage(event:MouseEvent):void
    {
        //navigateToURL(new URLRequest("http://www.google.com"), "_blank");
    }

    designClip.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

    function fl_MouseOverHandler(event:MouseEvent):void
    {
        var myTweenAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .4, 2, true);
    }

    designClip.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

    if(current_button != e.currentTarget)

    function fl_MouseOutHandler(event:MouseEvent):void
    {
        var myTweenAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .2, 2, true);
    }

    designClip.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

    if(current_button != null)
    {
    //current_buttontween your current button to normal
    //then we associate the new clicked button into the variable
    current_button = e.currentTarget as MovieClip;
    }

    function fl_MouseClickHandler(event:MouseEvent):void
    {
       
        var myTweenBigAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .8, 1, true);
        var myTweenSize:Tween = new Tween(designClip.yellow, "height", Strong.easeOut, designClip.yellow.height, 210, 3, true);
       
        //Other Clips Shrink
        var myTweenHomeSize:Tween = new Tween(Object(root).home.homeClip.orange, "height", Strong.easeOut, Object(root).home.homeClip.orange.height, 177, 3, true);
        var myTweenPhotoSize:Tween = new Tween(Object(root).photography.photoClip.white, "height", Strong.easeOut, Object(root).photography.photoClip.white.height, 177, 3, true);
        var myTweenMusicSize:Tween = new Tween(Object(root).music.musicClip.green, "height", Strong.easeOut, Object(root).music.musicClip.green.height, 177, 3, true);
        var myTweenAboutSize:Tween = new Tween(Object(root).about.aboutClip.blue, "height", Strong.easeOut, Object(root).about.aboutClip.blue.height, 177, 3, true);
       
        //all other buttons alpha to 20%
        var myTweenHomeAlpha:Tween = new Tween(Object(root).home.homeClip, "alpha", Strong.easeOut, Object(root).home.homeClip.alpha, .2, 2, true);
        var myTweenAPhotoAlpha:Tween = new Tween(Object(root).photography.photoClip, "alpha", Strong.easeOut, Object(root).photography.photoClip.alpha, .2, 2, true);
        var myTweenAMusicAlpha:Tween = new Tween(Object(root).music.musicClip, "alpha", Strong.easeOut, Object(root).music.musicClip.alpha, .2, 2, true);
        var myTweenAAboutAlpha:Tween = new Tween(Object(root).about.aboutClip, "alpha", Strong.easeOut, Object(root).about.aboutClip.alpha, .2, 2, true);
       
       
        function fl_ClickToGoToWebPage(event:MouseEvent):void
        {
        //navigateToURL(new URLRequest("http://www.google.com"), "_blank");
        }
    }

    tried to do it exactly as you said.

    I'm getting 3 errors.

    Symbol 'Design', Layer 'Layer 1', Frame 1, Line 35 1120: Access of undefined property e.
    Symbol 'Design', Layer 'Layer 1', Frame 1, Line 22 1120: Access of undefined property e.
    Symbol 'Design', Layer 'Layer 1', Frame 1, Line 20 1120: Access of undefined property fl_MouseOutHandler.


    what did i do wrong?

  7. #7
    Junior Member
    Join Date
    Apr 2006
    Posts
    28
    bump

  8. #8
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    Well, I can't see where you did as I said. I said it would be better to use MOUSE_DOWN and MOUSE_UP, instead of CLICK. You didn't do it.

    I'll try to explain what's the difference.
    CLICK event is dispatched when you press your mouse's left button and then release it. So you can only handle this event after these 2 phases are passed. MOUSE_DOWN occurs when you press the left button no matter whether you release it or not, and MOUSE_UP occurs when you release the button. This means you can handle all of those phases separately. You can do something when you press the button, something else when you release it. I hope it helps.


    As to your errors, that's typical, look, here you got the keyword "event"
    Actionscript Code:
    function fl_MouseOutHandler(event:MouseEvent):void
    {
        var myTweenAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .2, 2, true);
    }

    designClip.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

    if(current_button != null)
    {
    //current_buttontween your current button to normal
    //then we associate the new clicked button into the variable
    current_button = e.currentTarget as MovieClip;


    And then, inside the function you call:
    Actionscript Code:
    e.currentTarget
    I think it's clear enough that you have to call
    Actionscript Code:
    event.currentTarget
    Check your code once again

  9. #9
    Junior Member
    Join Date
    Apr 2006
    Posts
    28
    im a little confused on the e.currentTarget or event.currentTarget am i calling a specific target like designClip.currentTarget. I'm confused on how this function is used.

    Here is where i am.

    I use currentTarget to designate the current clip as target on mouseDown.

    then on roll out, make a statement that nullifies the actions if the current clip is set as currentTarget.

    then i need to set the currentClip as NOT current target when clicked outside.

    now i can only roll over once, then it sticks to the roll over alpha, even if i roll out.
    I have only applied this code to the design button so far.

    Actionscript Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    designClip.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToGoToWebPage);

    function fl_ClickToGoToWebPage(event:MouseEvent):void
    {
        //navigateToURL(new URLRequest("http://www.google.com"), "_blank");
    }

    designClip.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

    function fl_MouseOverHandler(event:MouseEvent):void
    {
        var myTweenAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .4, 2, true);
    }

    designClip.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

    function fl_MouseOutHandler(event:MouseEvent):void
    {
        if(designClip != event.currentTarget)
        var myTweenAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .2, 2, true);
       
    //do your mouse out actions, so it wont roll out if the button you just clicked is the current button
    }

    designClip.addEventListener(MouseEvent.MOUSE_DOWN, fl_MouseClickHandler);

    function fl_MouseClickHandler(event:MouseEvent):void
    {
        //if not null, it means a button has already been clicked so we want this old active button to return to normal
        if(designClip != null)
        {
        //current_buttontween your current button to normal
        //then we associate the new clicked button into the variable
        designClip = event.currentTarget as MovieClip;
        }

    //then we tween the current button to the high alpha
       
        //get url
        navigateToURL(new URLRequest("design.html"), "infoFrame");
       
        var myTweenBigAlpha:Tween = new Tween(designClip, "alpha", Strong.easeOut, designClip.alpha, .8, 1, true);
        var myTweenSize:Tween = new Tween(designClip.yellow, "height", Strong.easeOut, designClip.yellow.height, 210, 3, true);
       
        //Other Clips Shrink
        var myTweenHomeSize:Tween = new Tween(Object(root).home.homeClip.orange, "height", Strong.easeOut, Object(root).home.homeClip.orange.height, 177, 3, true);
        var myTweenPhotoSize:Tween = new Tween(Object(root).photography.photoClip.white, "height", Strong.easeOut, Object(root).photography.photoClip.white.height, 177, 3, true);
        var myTweenMusicSize:Tween = new Tween(Object(root).music.musicClip.green, "height", Strong.easeOut, Object(root).music.musicClip.green.height, 177, 3, true);
        var myTweenAboutSize:Tween = new Tween(Object(root).about.aboutClip.blue, "height", Strong.easeOut, Object(root).about.aboutClip.blue.height, 177, 3, true);
       
        //all other buttons alpha to 20%
        var myTweenHomeAlpha:Tween = new Tween(Object(root).home.homeClip, "alpha", Strong.easeOut, Object(root).home.homeClip.alpha, .2, 2, true);
        var myTweenAPhotoAlpha:Tween = new Tween(Object(root).photography.photoClip, "alpha", Strong.easeOut, Object(root).photography.photoClip.alpha, .2, 2, true);
        var myTweenAMusicAlpha:Tween = new Tween(Object(root).music.musicClip, "alpha", Strong.easeOut, Object(root).music.musicClip.alpha, .2, 2, true);
        var myTweenAAboutAlpha:Tween = new Tween(Object(root).about.aboutClip, "alpha", Strong.easeOut, Object(root).about.aboutClip.alpha, .2, 2, true);
       
       
        function fl_ClickToGoToWebPage(event:MouseEvent):void
        {
        //navigateToURL(new URLRequest("http://www.google.com"), "_blank");
        }
    }


    here is a link to the website so you can see how its behaving. remember new code is only applied to design button.

    http://gldmd.com/TESTSITE/index.html

  10. #10
    Junior Member
    Join Date
    Apr 2006
    Posts
    28
    bump

  11. #11
    Junior Member
    Join Date
    Jul 2010
    Posts
    8
    function fl_MouseOutHandler(event:MouseEvent)

    function fl_MouseOutHandler(e:MouseEvent)
    e.currentTarget or event.currentTarget based on what you got in the function
    Basically what this does is to get the object thats "starting" the function.

    lets say i got this: Blackbird.addEventListener(MouseEvent.CLICK, run);
    function run(e:MouseEvent) {
    var bird:String =e.currentTarget
    }

    the variable bird will in this case hold the object that started the function( in this case the Blackbird).

    Hope this helps

  12. #12
    Junior Member
    Join Date
    Apr 2006
    Posts
    28
    Quote Originally Posted by Shattering View Post
    function fl_MouseOutHandler(event:MouseEvent)

    function fl_MouseOutHandler(e:MouseEvent)
    e.currentTarget or event.currentTarget based on what you got in the function
    Basically what this does is to get the object thats "starting" the function.

    lets say i got this: Blackbird.addEventListener(MouseEvent.CLICK, run);
    function run(e:MouseEvent) {
    var bird:String =e.currentTarget
    }

    the variable bird will in this case hold the object that started the function( in this case the Blackbird).

    Hope this helps
    ok i don't get why its e.currentTarget what is "e"?

    and second you state Blackbird, but then at the var, its just bird. Is that a wild card for anything with "bird" in it?

    can someone give me an example of how to incorporate this into my code? I honestly get the concept, but i have no idea how to incorporate it because of the complexity of my code. (its complex for me)

    also can i use variables to clean up my code?

  13. #13
    Junior Member
    Join Date
    Jul 2010
    Posts
    8
    Ok i have simplified the code for you:
    in this code i have 2 buttons one is named "t" and the secound one is named "b".
    im running a if check to check if the button has been clicked or not. NOTISE if i click the secound button the if check for the first button resets. remember you have to add this for all your buttons on all your buttons!

    Actionscript Code:
    import flash.events.MouseEvent;
    var tClicked:int=0;
    var bClicked:int=0;
    t.alpha=0.3;
    b.alpha=0.3;

    t.addEventListener(MouseEvent.MOUSE_OVER, tovera);
    function tovera(e:MouseEvent) {
        if (tClicked==0) {
        t.alpha=0.5;
        }
    }
    t.addEventListener(MouseEvent.MOUSE_OUT, toveru);
    function toveru(e:MouseEvent) {
        if (tClicked==0) {
        t.alpha=0.3;
        }
    }
    t.addEventListener(MouseEvent.CLICK, toverc);
    function toverc(e:MouseEvent) {
        if (tClicked==0) {
        t.alpha=1.0;
        tClicked=1;
        bClicked=0;
        b.alpha=0.3;
        }
    }
    b.addEventListener(MouseEvent.MOUSE_OVER, bovera);
    function bovera(e:MouseEvent) {
        if (bClicked==0) {
        b.alpha=0.5;
        }
    }
    b.addEventListener(MouseEvent.MOUSE_OUT, boveru);
    function boveru(e:MouseEvent) {
        if (bClicked==0) {
        b.alpha=0.3;
        }
    }
    b.addEventListener(MouseEvent.CLICK, boverc);
    function boverc(e:MouseEvent) {
        if (bClicked==0) {
        b.alpha=1.0;
        bClicked=1;
        tClicked=0;
        t.alpha=0.3;
        }
    }

  14. #14
    Junior Member
    Join Date
    Jul 2010
    Posts
    8
    Here is the example FLA file:

    oh and also if you did trace(bird); the output would be Blackbird because thats the object in the string variable

    var bird=e.currentTarget;
    is the same as
    var bird=Blackbird;
    because e.currentTarget is set to Blackbird because the addEventListener that ran the function was added to a object named Blackbird.
    Attached Files Attached Files
    Last edited by Shattering; 07-21-2010 at 09:48 PM.

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