04-30-2012, 03:57 PM
|
#1
|
|
Member
Join Date: Apr 2012
Posts: 91
|
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.
|
|
|
04-30-2012, 04:19 PM
|
#2
|
|
Senior Member
Join Date: Jan 2011
Posts: 699
|
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
|
|
|
04-30-2012, 04:20 PM
|
#3
|
|
Senior Member
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,718
|
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.
|
|
|
04-30-2012, 04:54 PM
|
#4
|
|
Member
Join Date: Apr 2012
Posts: 91
|
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
|
|
|
04-30-2012, 05:21 PM
|
#5
|
|
Senior Member
Join Date: Jan 2011
Posts: 699
|
Where this mainIndex.swf & mainPage.swf are loaded?
And how they loaded?
Show some code you are currently working on.
__________________
Regards
arkitx
|
|
|
04-30-2012, 05:38 PM
|
#6
|
|
Member
Join Date: Apr 2012
Posts: 91
|
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
|
|
|
04-30-2012, 06:02 PM
|
#7
|
|
Member
Join Date: Apr 2012
Posts: 91
|
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.
|
|
|
04-30-2012, 07:28 PM
|
#8
|
|
Senior Member
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,718
|
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.
Last edited by abeall; 04-30-2012 at 07:31 PM.
|
|
|
04-30-2012, 08:38 PM
|
#9
|
|
Member
Join Date: Apr 2012
Posts: 91
|
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?
|
|
|
04-30-2012, 08:57 PM
|
#10
|
|
Senior Member
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,718
|
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.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 01:39 AM.
///
|
|