Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 6 of 6

Thread: Visibility Class

  1. #1

    Visibility Class

    I am trying to create a class that will set the visibility of all movieClips to false by default. I would like to call a function like showClip(box_mc, triangle_mc) and change the visibility of just these movieClips to true. I have started creating my "Cloak class" but definitely need some guidance. The errors vary based on several attempts I've made but here is what I have thus far.

    Code:
     
    package 
    { 
    import flash.display.MovieClip; 
    public class Cloak extends MovieClip
    { 
    public function Cloak() 
     { 
     box.visible = false;
        
     } 
     
     public function showClip(clipName:String):void
          {
            var c = clipName;
            c.visible = true;
          }
    } 
    }

  2. #2
    rather than create a new class to change one property, I would probably make a utility type class that says something like:

    Code:
    static public function changeVisibility (isVisible:Boolean ...args):void
    {
       var mc:MovieClip;
       var collection:Array = args[0] is Array ? args[0] as Array : args;
       for each (mc in collection)
           mc.visible = isVisible;
    }
    That is if you want to batch edit a whole bunch of MovieClips. If you plan to do only one or two, then I would suggest just editing them as MovieClips and forgo creating a new class. What's one extra line of code?
    email: jwopitz (at) gmail (dot) com
    blogs: http://jwopitz.wordpress.com
    check out the as3isolib

  3. #3
    also for more information about the ...(rest) thing check this out - http://livedocs.adobe.com/flex/3/langref/arguments.html
    email: jwopitz (at) gmail (dot) com
    blogs: http://jwopitz.wordpress.com
    check out the as3isolib

  4. #4

    Sorry, my implementation is still wrong

    I tried to implement your code, but i'm obviously doing something wrong. I continue to get this error : 1061: Call to a possibly undefined method changeVisibilty through a reference with static type Class.

    Here is the my code:

    Code:
     
    package 
    { 
     import flash.display.MovieClip; 
     public class Cloak extends MovieClip
     { 
      public function Cloak() 
      { 
     
     
      } 
     
      static public function changeVisibility (isVisible:Boolean, ...args):void
      {
          var mc:MovieClip;
           var collection:Array = args[0] is Array ? args[0] as Array : args;
           for each (mc in collection)
           mc.visible = isVisible;
      }
     } 
    }

    I am implementing the class as such:

    Code:
     
    Cloak.changeVisibility(false,box_mc,triangle_mc);
    Please advise accordingly, thanks for your help thus far.
    Last edited by as3_novice; September 30th, 2008 at 04:48 PM. Reason: Mistake in code

  5. #5

    I got it to work!!!!

    Silly me, I had mispelled "visibility" when calling the method. I also needed to add a comma "," after the first arg. Thanks a million!!!!

  6. #6
    There's a really easy way to set it all to invisible by default. Use override and super()
    And the ...args is the perfect approach Class would look kinda like this:
    Code:
    package {
     public class Cloak extends MovieClip {
      public override function addChild(mc:MovieClip) {
       //Changes the built-in addChild to also make the clip invisible
       super();
       mc.visible = false;
      }
      public static function changeVis(vis:Boolean, ...clips) {
       for(var i=0;i<clips.length;i++) {
        try{clips[i].visible=vis;}
        catch(e:Error) {/*wasn't a movieclip, try next one*/}
       }
      }
     }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012