A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: How to active my buttons when mc is opacity 100

  1. #1
    Member
    Join Date
    Jun 2009
    Posts
    40

    How to active my buttons when mc is opacity 100

    I have buttons inside/on window01/mc that are still active/clickable when the opacity is 0, I basically have a area on my website that if you click it opens the window corresponding to the button. how do I stop this? I only want the buttons to work when window01 is opacity 100. I'm not a pro at AS so please if you reply, walk me through it a bit or edit my code.

    http://frozen-gecko.net/quicky.htm

    just click in the blank black area below the nav bar and the window will appear. The normal way to get to this window is click products than the buttons.

    Code:
    import gs.TweenLite; 
    
    
    btn06.addEventListener(MouseEvent.CLICK,f2);
    function f2(e:Event){
    navigateToURL(new URLRequest("http://www.jmoneyaudio.com/"), "_self");
    
    }
    //first we're making sure none of your content windows are
    //being displayed when the movie launches
    window01.alpha=window02.alpha=window03.alpha=window04.alpha=window05.alpha=pwindow01.alpha=pwindow02.alpha=pwindow03.alpha=0;
    
    //this doesn't change: just listening for mouse clicks
    addEventListener(MouseEvent.CLICK,onClick,false,0,true);
    
    //this changes a bit. Rather than dealing with the visible
    //property of the windows, we'll be tweening alpha properties
    var isTweening:Boolean=false;
    function resetBool():void {
        isTweening=false;
    }
    function onClick(e:MouseEvent):void {
        if (!isTweening) {
            isTweening=true;
            switch (e.target) {
                case btn01 :
                    closeWindows();
                    TweenLite.to(window01,1,{alpha:1,overwrite:false,onComplete:resetBool});//this is a call to
                    //the TweenLite class you set up earlier: The first parameter is the
                    //display object you're targeting (window0x), the second param is
                    //length of time the tween will take to complete in whole seconds
                    //(1 second), then all properties for the display object are listed in
                    //the third param within {}, in this case we're changing the alpha
                    //from 0 to 1 and we don't want this tween call to interrupt/overwrite
                    //any previous tween calls
                    break;
                case btn02 :
                    closeWindows();
                    TweenLite.to(window02,1,{alpha:1,overwrite:false,onComplete:resetBool});
                    break;
                case btn03 :
                    closeWindows();
                    TweenLite.to(window03,1,{alpha:1,overwrite:false,onComplete:resetBool});
                    break;
                case btn04 :
                    closeWindows();
                    TweenLite.to(window04,1,{alpha:1,overwrite:false,onComplete:resetBool});
                    break;
    			case btn05 :
                    closeWindows();
                    TweenLite.to(window05,1,{alpha:1,overwrite:false,onComplete:resetBool});
                    break;
    				
    			case window01.pbtn01 :
                    closeWindows();
                    TweenLite.to(pwindow01,1,{alpha:1,overwrite:false,onComplete:resetBool});
                    break;
    				
    			case window01.pbtn02 :
                    closeWindows();
                    TweenLite.to(pwindow02,1,{alpha:1,overwrite:false,onComplete:resetBool});
                    break;
    				
    			case window01.pbtn03 :
                    closeWindows();
                    TweenLite.to(pwindow03,1,{alpha:1,overwrite:false,onComplete:resetBool});
                    break;
    
                default :
                    return;
            }
        }
    } 
    
    function closeWindows():void{
    //for each of these ifs we're looking for the object that is currently
    //being displayed (we know this because it's alpha will be equal to 1)
    //and then tweening its alpha property down to 0 over 1 second
    if(window01.alpha==1) TweenLite.to(window01,1,{alpha:0});
    else if(window02.alpha==1) TweenLite.to(window02,1,{alpha:0});
    else if(window03.alpha==1) TweenLite.to(window03,1,{alpha:0});
    else if(window04.alpha==1) TweenLite.to(window04,1,{alpha:0});
    else if(window05.alpha==1) TweenLite.to(window05,1,{alpha:0});
    else if(pwindow01.alpha==1) TweenLite.to(pwindow01,1,{alpha:0});
    else if(pwindow02.alpha==1) TweenLite.to(pwindow02,1,{alpha:0});
    else if(pwindow03.alpha==1) TweenLite.to(pwindow03,1,{alpha:0});
    } 
    
    
    
    //BTN STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    btn01.alpha=.60; 
    btn02.alpha=.60; 
    btn03.alpha=.60; 
    btn04.alpha=.60; 
    btn05.alpha=.60; 	
    btn06.alpha=.60;
    window01.pbtn01.alpha=.60;
    window01.pbtn02.alpha=.60; 
    window01.pbtn03.alpha=.60;
    
    
    btn01.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    btn01.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    btn02.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    btn02.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    btn03.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    btn03.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    btn04.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    btn04.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    
    btn05.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    btn05.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    btn06.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    btn06.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    window01.pbtn01.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    window01.pbtn01.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    window01.pbtn02.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    window01.pbtn02.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    window01.pbtn03.addEventListener(MouseEvent.MOUSE_OVER,onBtnOver,false,0,true);
    window01.pbtn03.addEventListener(MouseEvent.MOUSE_OUT,onBtnOut,false,0,true);
    
    
    function onBtnOver(e:MouseEvent):void{
    TweenLite.to(e.target, 0.8, {alpha:1});
    }
    function onBtnOut(e:MouseEvent):void{
    TweenLite.to(e.target, 0.8, {alpha:0.6});
    }
    Last edited by FrozenGecko; 07-26-2009 at 12:55 AM.

  2. #2

  3. #3
    Member
    Join Date
    Jun 2009
    Posts
    40
    could you elaborate? I said im not a AS pro

  4. #4
    Member
    Join Date
    Jun 2009
    Posts
    40
    -bump- fixed some wording that may have been alittle confusing

  5. #5
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    You can set the "enabled" flag to false as cresquin pointed out (that should toggle at the same time you turn alpha on and off) - or you could use visibility rather than alpha (if you're doing it with TweenLite switch to autoAlpha to handle that automatically).

    Or you could brute-force it and just do a logic check: if(btn01.alpha == 1){ whatever }

  6. #6
    Member
    Join Date
    Jun 2009
    Posts
    40
    Option 1 sounds good, but like i said "I AM A FING NOOB" could you post some examples of the code i should use or what i should edit in my current code x.X

  7. #7
    Member
    Join Date
    Jun 2009
    Posts
    40
    would you recommend me changing to frameLabels? and if so, how would I tween with that method?

  8. #8
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    Do what cresquin and neznein9 said. Something like;

    if(myButton.alpha<100){
    myButton.enabled=false;
    }

    Or whatever. Use the if statement to test if the button is solid, and then enable or disable the button.
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

  9. #9
    Member
    Join Date
    Jun 2009
    Posts
    40
    thank you very much for actually posting a piece of code =p i'll give to a go asap

  10. #10
    Member
    Join Date
    Jun 2009
    Posts
    40
    if(myButton.alpha<100){
    myButton.enabled=false;
    }

    didn't work

  11. #11
    Member
    Join Date
    Jun 2009
    Posts
    40
    is there any way to use that type of code, but instead just tell it to stop listening for its mouse clicks until its opacity is above x number

  12. #12
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    Sorry, my code wasn't meant as something usable, it was hypothetical.

    Let me see if I can find something more copy/paste-able.

    Maybe if you could explain/screenshot the problem better, I didn't really see what the problem was with your gallery/site.
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

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