Results 1 to 6 of 6
Thread: Visibility Class
-
September 30th, 2008, 10:06 AM #13Registered User
postsVisibility 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; } } }
-
September 30th, 2008, 02:17 PM #2
rather than create a new class to change one property, I would probably make a utility type class that says something like:
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?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; }
-
September 30th, 2008, 02:18 PM #3
also for more information about the ...(rest) thing check this out - http://livedocs.adobe.com/flex/3/langref/arguments.html
-
September 30th, 2008, 04:47 PM #43Registered User
postsSorry, 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:
Please advise accordingly, thanks for your help thus far.Code:Cloak.changeVisibility(false,box_mc,triangle_mc);
Last edited by as3_novice; September 30th, 2008 at 04:48 PM. Reason: Mistake in code
-
September 30th, 2008, 04:50 PM #53Registered User
postsI 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!!!!
-
September 30th, 2008, 05:28 PM #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*/} } } } }

Reply With Quote

Bookmarks