views:

2060

answers:

4

Hi, OK - weird problem which happens each time - and so I'm thinking I must just be missing something very obvious.

If in Flash CS3 I drag a Button component to the stage, and in the Document Class I hide that button with visible = false; - it works fine. However, if I change the label of that Button from it's default 'Label' to anything else, the button does not go invisible...

eg. Button named hide_btn, Document Class Foo:

package {   
    import flash.display.MovieClip;

    public class Foo extends MovieClip{
     public function Foo(){
      hide_btn.visible = false; // Works ONLY if I didn't change the button label!!
     }
    } 
}

The Button is (correctly) invisible when I run the movie... If I change the label to, say, 'LabelX' - then the Button is still there...

So surely someone would have noticed this before if it were a bug, right?? So - can someone explain what is going on?

Cheers.

PS. A trace of trace(hide_btn.visible) says false, even though it clearly isn't...

+2  A: 

Funky one!

Didn't expect that :)

I had sort of a similar issue...well not quite. I was trying to access some clips in a later frame of a movieclip, just like in as2, but unless the playhead goes to that frame, in as3, the clips are null.

The workaround is to force the stage to invalidate and access the objects in the RENDER event ( which I think happens right before all the stuff gets rendered on stage, but after all your stuff is ready/accessible )

My guess is since you set the label in the Parameters tab, that gets evaluated after the Document class constructor, so there might be something in the Button Component invalidation that tells it to be visible. It's safer to set it invisible after all that is done.

Here is the updated code...famous last words: 'it works for me' :)

   package {   
    import flash.display.MovieClip;
    import flash.events.Event;
    public class Foo extends MovieClip{
        public function Foo(){
      //stage.invalidate() forces the stage to re-evaluate itself
         stage.invalidate();
      stage.addEventListener(Event.RENDER, stageRenderHandler);
        }
     //the RENDER events gets fired when invalidation is done
     //and everything is ready to be displayed/rendered
     private function stageRenderHandler(event:Event):void{
      hide_btn.visible = false; // Works
     }
    }   
}
George Profenza
Cheers George - yes that works for me to! Strange something so common would actually require a work-around!But I think you are right - something inside the Button is making it visible after I make it invisible.Guess a simple get-out other than your solution is to just use script to change a label, or stick everything in a movieclip/sprite and make that invisible..
No problem. You're right about this strange behaviour. I use the ui components pretty often, but haven't came across this one so far.If you're happy with the answer you can mark it as a solution ;)
George Profenza
I added a comment on this last night, and today its gone! Anyway, this behaviour persists, even with the solution given above. I used the exact code and if you change the label of the button, the button will still remain visible. I have been fighting this same issue.
JasonMichael
A: 

Okay, I don't believe the solution has been posted, though I think the suggested solution are very cool and useful for test purposes. I tried invalidating the stage and the problem still persists with a new flash file with nothing but the code given... as soon as I change the label, I can't hide the button. Before changing the label, it works.

I think the best solution may be to create a button object or somehow export the button to be used by actionscript, and then set the position, visibility and label properties, afterward. I'm going to try this tonight and will let you know how it works. I have a huge project that this issue is holding up...

JasonMichael
are you uing the Button Component ( fl.controls.Button ) ?
George Profenza
A: 

Here is the solution:

For any such button you are having this problem with, right click it, convert to symbol and select Movie Clip (unless you want it to be something else, fo course). Change the name from Symbol1 to something more descriptive (previous_btn worked for me). In the Linkage section of this dialog box, choose "Export for Actionscript" and "Export to First Frame" (if that works for you - first frame is usually my preference).... Click Okay.

Right click the button again, and choose edit, and change the label from the properties button. Change the size to your desired proportions (H and W), then click your Scene (i.e. Scene 1) to get out of edit mode. Test and enjoy, it works reliably now. This is easier than writing the code to create the button from a movie clip.

JasonMichael
A: 

If you wait to hide your button components until after the initial load .visible = false will work. for example in the constructor setting myBtnComponent.visible = false will NOT work, instead add this into to the constructor

public function your constructor { loaderInfo.addEventListener(Event.COMPLETE, init); }

then

private function init(e:Event):void { loaderInfo.removeEventListener(Event.COMPLETE, init); myBtnComponent.visible = false }

I believe that the components will load their initial settings from the compnent inspector when the application first launches, so by listening for the initial loaderInfo complete event, you can then change the properties of your components after they have instantied.

-Dave-

Dave