dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Actionscript MouseEvent Help!

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    10

    Actionscript MouseEvent Help!

    Hey All,

    I'm not an expert at flash, but I understand animation and all that, however I'm having a bit of trouble with writing the actonscript for my flash file.

    I have a sliding information panel that comes up when you click a button, which displays information. I have it sliding up on click, but I can't seem to get it to go back down when I click it again.

    The Animation is 40 frames long, Frame one is the panel completely out of sight, Frame 20 is the panel in full view, and FRame 40 is the panel completely out of sight again.
    Here is the code:

    Code:
    panel1_mc.panelWelcome_mc.popUp1_btn.addEventListener(MouseEvent.CLICK, clickF);
    panel1_mc.panelWelcome_mc.popUp1_btn.addEventListener(MouseEvent.CLICK, deselectF);
    
    function clickF(event:MouseEvent):void{
    	if(panel1_mc.currentFrame <<2){
    		panel1_mc.play();
    	}
    
    }
    
    function deselectF(event:MouseEvent):void{
    	if(panel1_mc.currentFrame == 20){
    		panel1_mc.gotoAndPlay(21);
    	}
    }
    I have no idea, but I'm wondering if it could have something to do with the stop(); command I have on Frame 20?\

    Would be so appreciative if someone could enlighten me as to my problem

    Cheers

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Instead of having two different functions trigger, you could have combined into a single function. But that's not actually your problem. Your problem is that << is the bitwise left shift operator, not a comparison. So every time you click, you're testing whether currentFrame * 4 is not 0. It won't be, so that will evaluate to true and it will trigger the first case again. Try this:
    Code:
    panel1_mc.panelWelcome_mc.popUp1_btn.addEventListener(MouseEvent.CLICK, clickF);
    
    function clickF(event:MouseEvent):void{
    	if(panel1_mc.currentFrame <=2){
    		panel1_mc.play();
    	}else{
    		panel1_mc.gotoAndPlay(21);
            }
    }
    Additionally, unless your animation is complex, you could just use a tweening engine to tween it up and down and not have to deal with mulitple frames.

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    10
    Thanks for your reply!

    I switched my code with yours, and tested, and nothing appears to have changed,
    When I click the button, it slides up, but when i hover back over the button, it seems to have a disappeared (I'm not getting the 'hand' that shows up when you hover a link).

    Would this have something to do with the button itself?

    Thanks again for your help

    Cheers

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    10
    Disregard that last post.
    I just went into my animation to check what happens to my button when I test,
    (Basically the panel sits directly below the stage -with a mask showing only my stage- and the button -which sits over text- is at the very top of my stage)
    and lo and behold! because the button is in the same layer as the panel, when the panel moves up, so too does the button, pushing it out of the stage!

    So I simply moved the button up one layer, so it wasn't moving with the panel animation!
    Perfect! Thanks for your code fix!

    Cheers

  5. #5
    AS3 N00B
    Join Date
    Feb 2002
    Location
    NYC
    Posts
    308

    Help with loops

    sorry disregard this post.
    -Neo

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