hey,
i consider myself a newbie in as3, hence, i bump into a lot of problems. here is the latest:
main.swf has Main.as as document class
package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
/**
* ...
* @author sQrt121
*/
public class Main extends MovieClip
{
public function Main()
{
addEventListener( Event.ADDED_TO_STAGE, init );
}
private function init(e:Event):void
{
removeEventListener( Event.ADDED_TO_STAGE, init );
// comment / uncomment the following line
//MyStatic.doNothing();
var _lLoader1:Loader = new Loader();
var _urlReq1:URLRequest = new URLRequest("1.swf");
_lLoader1.contentLoaderInfo.addEventListener(Event.COMPLETE,
swfLoaded);
_lLoader1.load(_urlReq1);
var _lLoader2:Loader = new Loader();
var _urlReq2:URLRequest = new URLRequest("2.swf");
_lLoader2.contentLoaderInfo.addEventListener(Event.COMPLETE,
swfLoaded);
_lLoader2.load(_urlReq2);
}
private function swfLoaded(e:Event)
{
addChild(e.currentTarget.content)
}
}
}
1.swf has ClassOne.as as document class
package
{
import flash.display.MovieClip;
import flash.events.Event;
/**
* ...
* @author sQrt121
*/
public class ClassOne extends MovieClip
{
public function ClassOne()
{
addEventListener( Event.ADDED_TO_STAGE, init );
}
private function init(e:Event):void
{
removeEventListener( Event.ADDED_TO_STAGE, init );
trace( MyStatic.compute())
}
}
}
1.swf has ClassTwo.as as document class
package
{
import flash.display.MovieClip;
import flash.events.Event;
/**
* ...
* @author sQrt121
*/
public class ClassTwo extends MovieClip
{
public function ClassTwo()
{
addEventListener( Event.ADDED_TO_STAGE, init );
}
private function init(e:Event):void
{
removeEventListener( Event.ADDED_TO_STAGE, init );
trace( MyStatic.compute())
}
}
}
MyStatic.as is a “static” class
package
{
/**
* ...
* @author sQrt121
*/
public class MyStatic
{
private static var nNumber:uint;
public function MyStatic()
{
}
public static function compute():uint
{
nNumber += 10;
return nNumber
}
public static function doNothing():void
{
}
}
}
when i test the main.fla, it traces 10, 10. if i uncomment line 24, it traces 10, 20. in other words if i dont make a referance to the MyStatic class in the Main.as (i.e the class becomes part of main.swf), i end up with 2 separate “static” classes.
finaly my question :
is there a better way (other than making it part of the “supreme parent”) to create a “unique” static class that is visible everywhere inside a project no matter where u use it (first)?
from what i know, i think the answer is “no”, but like i said, im no expert
additional info:
ive been using swfaddress( a static class) in my projects for sometime now, but the supreme parent was always the main.swf. now im working on a project that requires a preloader - so this will be the supreme parent. inserting a referance (e.g a trace) to the swfaddress class inside the preloader.as doesnt seem that elgant to me…