0

I have two swf, A.swf and B.swf: B.swf is a child of A.swf.i want to access the variable of a.swf in b.swf.Is it Possible?How Can i do this? please Explain With Example. Thanks in Advance

loader.load(new URLrequest"b.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded)
function swfLoaded(e:Event):void
{
 data= e.target.content;    //data is the String  i declared outside                
 mainContainer.addChild(loader);In this Loader i want to dispaly the data
}
Mercy
  • 1,862
  • 9
  • 39
  • 75

3 Answers3

0

YES, possible.

var myObj:Object = new Object();
var swfLoader:Loader = new Loader();

var swfFile:URLRequest=new URLRequest("b.swf");
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadedHandler);
swfLoader.load(swfFile);

private function swfLoadedHandler(e:Event):void {
    myObj = e.target.content;
    //trace(myObj.mcBanner.prevImage);
}

Now myObj var containes the loaded SWF contents. U can access easily.

Benny
  • 2,250
  • 4
  • 26
  • 39
0

Assume this is the document Class in b.swf:

public Class B extends MovieClip {
   protected var _theVar:String;
   public function get theVar():String {
      return _theVar;
   }
   public function set theVar(value:String):void {
      if (value != _theVar) {
         _theVar=value;
         //do something here with the new value
      }
   }
   public function B () {
      super();
   }
}

in a's document Class:

//this will be inside a function that detects that the content has been loaded
var bContent = yourLoader.loaderInfo.content as B;
bContent.theVar = 'some value';
Amy Blankenship
  • 6,485
  • 2
  • 22
  • 45
  • -1 because this will compile class B into class A. This is REALLY bad practice. – Creynders Nov 10 '11 at 14:24
  • It really depends on how much is actually in Class B (the as). It's not going to compile the symbol information from the timeline. IMO, users asking such questions are not ready for Interfaces. – Amy Blankenship Nov 10 '11 at 17:11
  • I understand, but still... Teach a man how to fish... And since they're not using interfaces, it's not only the document class that gets compiled in, but everything it depends on, which (when not using interfaces) tends to be 100% of the code. – Creynders Nov 11 '11 at 10:16
0

If you just want to pass a value to the loaded swf you can use the parameters object, see AS3 Pass FlashVars to loaded swf

Community
  • 1
  • 1
Creynders
  • 4,573
  • 20
  • 21
  • i saw that link sir Multiple markers at this line: -1046: Type was not found or was not a compile-time constant: URLVariables. -1180: Call to a possibly undefined method URLVariables.i got error – Mercy Nov 10 '11 at 15:02
  • Ummm, you shouldn't be copying the question, but the answer. – Creynders Nov 11 '11 at 10:16