Search code examples
actionscript-3flashdispatcheventgsap

AS3 change item visibility if variable goes below X amount


I've attached a source file below, I'm kinda stuck.

Basically, its an FLA that has a variable that changes (smscounter) based on whatever number is read in from an XML file (on my server). There is a big movieclip called "rewinder" on frame 1 of the main stage. There are left and right buttons that navigate between frames within that movieclip "rewinder". What I'm trying to do in theory is:

if(frame != 2) {button_right.visibility = true};
if(frame == 2 && smscounter > 5) {button_right.visibility = true};
if(frame == 2 && smscounter < 5) {button_right.visibility = false}

I've been told that won't work simply because once a variable (visibility) is set, it's not going to just continually check it, so I have to dispatch an event? I've tried 3-4 tutorials and I can't get any to work.

Now a few things:
- I would LOVE to avoid anything super complicated. All I need is on frame 2 for the button to not be there IF smscounter is below 5. Other tutorials required another class and document class, but I couldn't get them working
- The buttons are currently outside the rewinder movieclip. I put them inside and on each frame, but then I couldn't get them to react to a rollover.
- The code is about as optimized as if a first grader wrote it, mainly because I'm a designer and I've been having help along the whole way with this.
- Greensock LoaderMax is being used to put the videos and sound in. Not super relevant to the problem, I just left them in there to give a better picture of what I'm working on.

Link to FLA and source files: http://www.mediafire.com/download.php?ejy6j9h9r1c1829


Solution

  • you can add this code to the main timeline looks like you can only go to frame 2 and 3, but you have a total of 21 frames (from voltagebar) that's why I used the numbers instead of 1 and totalFrames.

    rewinder.addEventListener(Event.ENTER_FRAME,checkButtons);
    function checkButtons(e:Event):void{
        if(rewinder.currentFrame <= 2){
            button_left.visible = false;
        }else{
            button_left.visible = true;
        }
    
        if(rewinder.currentFrame >= 3){
            button_right.visible = false;
        }else{
            button_right.visible = true;
        }
    }