The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

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