Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-30-2012, 03:57 PM   #1
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default Global Class

I'm a total Nubbie and its possible that this has been answer but I cant find it any where.

So my question is this:

is there an AS3 global class that can access multiple swfs Movie Clips?

Like a kind of GLOBAL VAR where all movie clips can be stored then referenced later on from any swf, any time, any where???



--------------------------------------------------------------------------

Your power is fading, Ming.
Mighty Flash Gordon is offline   Reply With Quote
Old 04-30-2012, 04:19 PM   #2
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

Welcome Mighty Flash Gordon


Instead of asking for a solution why don't you describe what you want to do?

That will be more clear to us and you will get a better solution.


__________________
Regards

arkitx
arkitx is offline   Reply With Quote
Old 04-30-2012, 04:20 PM   #3
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,812
Send a message via AIM to abeall
Default

In AS3 you use static class properties for global variables. You could re-create identical behavior to the _global property in AS2 but it's not really encouraged.
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Old 04-30-2012, 04:54 PM   #4
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default

well basically i was working on a multiple swf website for e.g.

mainIndex.swf (which has buttons on stage, main, company,contact, about e.t.c.)loads in mainPage.swf (which has mc's that tween on stage)

companyPage.swf (which has mc's that tween on stage)
contactPage.swf (which has mc's that tween on stage)
aboutPage.swf (which has mc's that tween on stage)

then if I press the companyPage button the mainPage.swf movie clips tween of stage then unloads then companyPage.swf loads and the mc's tween on stage and so on.

So instead of the swfs just unloading/loading there is a little more flow to the website.

I don't like websites that just jump between pages.

Last edited by Mighty Flash Gordon; 04-30-2012 at 05:02 PM. Reason: forgot to put dont instead of do
Mighty Flash Gordon is offline   Reply With Quote
Old 04-30-2012, 05:21 PM   #5
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

Where this mainIndex.swf & mainPage.swf are loaded?

And how they loaded?

Show some code you are currently working on.




__________________
Regards

arkitx
arkitx is offline   Reply With Quote
Old 04-30-2012, 05:38 PM   #6
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default

Im using greensock's timelineMax, tweeners and loaders e.t.c.

I have a container added to the stage from the mainIndex.swf library called swfContainer_mc:

ActionScript Code:
var swfContainer_mc:swfContainer = new swfContainer; addChild(swfContainer_mc); var mainPageloader:SWFLoader = new SWFLoader("mainPage.swf",{name:"mainPageSWF",container:swfContainer_mc,x: -  swfContainer_mc.width / 2,y: -  swfContainer_mc.height / 2,onInit:initHandler,estimatedBytes:9500}); function initHandler(e:LoaderEvent):void         {                         // fade the swf in as soon as it inits             TweenMax.from(e.target.content,1,{delay:2, alpha:0});             // get a MovieClip named "mcOne" e.t.c. that's on the root of the subloaded swf in this case "_pageD.swf"             var mcOne_mc:DisplayObject = mainPageloader.getSWFChild("mcOne");             var mcTwo_mc:DisplayObject = mainPageloader.getSWFChild("mcTwo");             var mcThree_mc:DisplayObject = mainPageloader.getSWFChild("mcThree");             mcOne_mc.alpha = 0;             //mcTwo_mc.alpha = 0;             mcThree_mc.alpha = 0;             // find the "com.greensock.TimelineMax" class that's inside the subloaded swf             var timelineMax:Class = mainPageloader.getClass("com.greensock.TimelineMax");             // then you can create an instance of TimelineLite like:             var enterStage:Object = new TimelineMax({tweens:[new TweenMax(mcOne_mc,0.5,{alpha:0,x:"0"}),                                                          TweenMax.to(mcOne_mc,0.5,{delay:2,alpha:1,x:"491"}),                                                          TweenMax.from(mcTwo_mc,0.5,{alpha:0,x:"491",tint:0x000000}),                                                          TweenMax.to(mcThree_mc,0.5,{alpha:1,x:"491",tint:0xFF0000})],                                                          align:TweenAlign.SEQUENCE});}

and the mainPage.swf has mc's on stage and for now I have named them:
mcOne
mcTwo
mcThree
e.t.c.

Last edited by Mighty Flash Gordon; 04-30-2012 at 05:44 PM. Reason: forgot to add something in the code
Mighty Flash Gordon is offline   Reply With Quote
Old 04-30-2012, 06:02 PM   #7
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default

I forgot to mention that this does work but I was wondering if there was a global class so it would be a lot easier to reference mc's inside all swf's. I did read some where that it is'nt wise to use global variables because it can lead to spaghetti code but I dont know how else one would reference mc's easily in multiple swf's.
Mighty Flash Gordon is offline   Reply With Quote
Old 04-30-2012, 07:28 PM   #8
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,812
Send a message via AIM to abeall
Default

There is no global class.

You can make one pretty easy:

ActionScript Code:
// Global.as package {     public class Global {         private static var _globals:Object = {};         public static function get globals():Object {             return _globals;         }     } } // From anywhere: Global.globals.myVariable = "whatever"; trace(Global.globals.myVariable); // And to get AS2 style syntax: // _global.as package {     public function get _global():Object {         return Global.globals;     } } // From anywhere: _global.myVariable = "whatever" trace(_global.myVariable);

Using a global class is not really best practice in AS3, though.
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter

Last edited by abeall; 04-30-2012 at 07:31 PM.
abeall is offline   Reply With Quote
Old 04-30-2012, 08:38 PM   #9
Mighty Flash Gordon
Member
 
Join Date: Apr 2012
Posts: 91
Default

That looks simple enough to understand.
"Using a global class is not really best practice in AS3, though."
Hmmm thats what I thought.

So what is the best way to access mc's from other swf's easily?
Mighty Flash Gordon is offline   Reply With Quote
Old 04-30-2012, 08:57 PM   #10
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,812
Send a message via AIM to abeall
Default

Just create public properties on the child SWFs. It looks like you are almost doing that with a public method and a string key... that's basically what a property is, a public named key.
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:21 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.