Results 1 to 8 of 8

Thread: Can you script Flash to show/hide layers on the timeline?

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default Can you script Flash to show/hide layers on the timeline?

    Has anyone tried to do this? Namely control usable/viewable content by turning on or off a whole timeline layer?

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by evan View Post
    Has anyone tried to do this? Namely control usable/viewable content by turning on or off a whole timeline layer?
    You can't control layers with ActionScript. Layers are more of a tool within the Flash IDE, they have no bearing on ActionScript. In ActionScript, the top most layer is the same thing as the bottom most.

    You can certainly hide/show individual movieclips though, or even remove them from the stage entirely.

    You could add all the movieclip on a certain layer to an array and then loop through them to make the all hide. But that's the closest you'd get to "turning off" a layer.

  3. #3
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    one quick and easy way would be to put everything in a layer into one movie clip and call it layer "x" or whatever, and if the user doesn't want it, you can unload or just make that movie clip transparent... of course every time you had a keyframe on that layer, you'd need a different movieclip

  4. #4
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    so, this actually accomplishes the same thing. I can make a movie symbol with a grouping of graphics or buttons, put them into a movie clip and load/unload (or use _alpha ) and that takes care of it.

    If there are buttons that have functions that are called up in the first keyframe, would that mess up their interactivty? (I did a simple AS3.0 project and if I removed buttons from the timeline and put them back -they stopped working when I put them back -making them "dissapear" with _alpha or moving them off the stage for a set amout of frames helped -but I'm sure there was a better way.)

  5. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    If you remove things from the stage - actually remove them, not just hide them - and then bring them back, you'll have to reassign all behavior associated with that movieclip.

    In essence, you're never adding back the same movieclip that you removed. It might be a duplicate of the one you removed, but it's a different instance. So, when you add a movieclip back in, you have to reassign events to it.

    You could use a listener object to assign these dynamically.

    Evan, in what context are you looking to implement such functionality? With the toolbar? If so, in what form?

    What mpstar is a valid option, but for that, you have to use timeline dependant objects. To create a dynamic application (such as your toolbar) it's almost always better to call things at run time. But then again, that all depends on the application. If it's lightweight, timeline driven is fine. If you plan to make it feature rich, you might want to savor every bit of processing power that you have.
    Last edited by Medyman; 05-13-2008 at 12:52 AM.

  6. #6
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    I was reffering to another project, actually this was a scrolling backgound with three doors -the flash movie was about 800 px wide and the background graphic was about 2500 px -I didn't know how to do the actionscript at the time so I did alot of tweening.

    In most cases the scrolling is done with actionscript and mouse events to scroll left or right. The specs called for actual buttons on the main graphic background that would trigger the scrolling. I wanted the buttons to stop being "hot" righ after they were clicked, so I set the alpha to 0 and moved them off the stage. They were either just 0 alpha hotspots -or they were perfect copies of things they were covering up -with animated "over" states.


    The code looked something like this:

    stop();
    /*directional buttons*/
    sudiotomall_btn.addEventListener(MouseEvent.MOUSE_UP,eventResponse1);
    function eventResponse1(evt:MouseEvent):void {
    gotoAndPlay("studio_to_mall");}


    studiotogrownups_btn.addEventListener(MouseEvent.MOUSE_UP,eventResponse2);
    function eventResponse2(evt:MouseEvent):void {
    gotoAndPlay("studio_to_grownups");}


    malltostudio_btn.addEventListener(MouseEvent.MOUSE_UP,eventResponse3);
    function eventResponse3(evt:MouseEvent):void {
    gotoAndPlay("mall_to_studio");}


    grownupstostudio_btn.addEventListener(MouseEvent.MOUSE_UP,eventResponse4);
    function eventResponse4(evt:MouseEvent):void {
    gotoAndPlay("grownups_to_studio");}

    //Start over button
    home_btn.addEventListener(MouseEvent.MOUSE_UP,eventResponse5);
    function eventResponse5(evt:MouseEvent):void {
    gotoAndPlay("start");}
    The functions are in AS 3.0 to get used to it somewhat -even though I didn't need to.
    -anyway -my original question for this post was still in search of what is and what IS NOT possible in flash.

  7. #7
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Maybe I'm missing the point, but if you're using invisible hotspots, you can certainly delete the mouse event associated with it after you click.

    In AS2 (because it's easier to "read"):
    Code:
    movieclip.onRelease = function() {
       delete this.onRelease
    }
    That would mean that the button only works for one click. In AS3, you could remove the event listener.

    There isn't a need to add/remove layers (based on my understanding of what you're trying to do).

    Or there is alwasys the _visible property. It's one step between removing the MC from the stage and using alpha = 0. It doesn't remove the MC from the stage, but gets rid of it visually and functionaly. Alpha=0 only gets rid of it visually (i.e. you can still click on a button with alpha=0). The button also retains the actions associated with it.

  8. #8
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    initially the question wasn't geared even to this -I asked it in the abstract so as I plan in the future -I know the easiest thing to do -ie disable a layer is not possible,

    Moving on, I can think that if I were to do this project again, I might want to set up some kind of conditional statement up in the frame where the button would be useful and turn it on and then turn it off.

    would I do that in AS 3.0 by turning on/off event listeners?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •