views:

168

answers:

2

Very weird problem, I am new to AS, but I have to say it's hard to comprehend AS is a modern language:


      private function completed():void
      {    
       trace("completed.");    
       var player:Object = (loader.content as SystemManager).application as Object;
       player.playVideo();
       player.setSize(200,300);
      }


    SWFLoader id="loader" horizontalCenter="0" width="100%" height="362" source="http://localhost:8000/testflv1.swf" init="completed()"

What I want to do is embed a swf in another parent swf, and call a function from parent to the embedded swf. Then, I use the init event for the SWFLoader to invoke the method. Before doing this I have verified that using the same code in a button click handler, it is fine with:

var player:Object = (loader.content as SystemManager).application as Object;

But if in a init event handler, the (loader.content as SystemManager).application is a null.

Whereas, in the document of SWFLoader:

init Dispatched when the properties and methods of a loaded SWF file are accessible.

+1  A: 
Mad Oxyn
Thanks, but it can't work. the Error is: <pre>Property playVideo not found on _testflv1_mx_managers_SystemManager and there is no default value</pre>I have the playVideo defined in the swf file embedded:<pre><code> public function playVideo():void { // Alert.show('playVideo'); svid.play(); return; }</code></pre>
Bin Chen
If I catch the event of a button - click the button to invoke the embedded swf's method, it will work with Object way(declare player to be an Object), but not the MovieClip way! That's really weird.
Bin Chen
I have modified the answer, does this work for you now?
Mad Oxyn
it still can't work, in the line of: loadedSM = SystemManager(loader.content); the error is: TypeError: Error #1034: Type Coercion failed: cannot convert _testflv1_mx_managers_SystemManager@6cd3479 to mx.managers.SystemManager.)
Bin Chen
that is odd, it works for me. is it possible for you to paste some simple sources in here which reproduces your problem?
Mad Oxyn
A: 

I have the same problem... it works when I test local, but when I download the flexapp(.swf) from a webserver, SystemManager isn't a SystemManager...

Gertjan