How to load an external swf to the main stage from an instanced child class?

Posted by RaamEE on Stack Overflow See other posts from Stack Overflow or by RaamEE
Published on 2010-04-15T12:38:15Z Indexed on 2010/04/15 12:43 UTC
Read the original article Hit count: 172

Filed under:
|
|
|
|

Hi,

I am trying to get an instance of a class to the load an external swf and show it. So far I have the following: 1) I wrote a class that uses the Loader class to load an external swf "loadExtSWF". 2) I have a fla named "MainSWF.fla" that uses a document class "MainSWF.as". 3) I have the MainSWF.as file that instances "loadExtSWF" and calls loadExtSWF.startLoad to load the swf.

This almost works. The instance of loadExtSWF loads the external swf, but the swf is not displayed.

If I replace the fla's document class with loadExtSWF (this has an empty constructor) instead of MainSWF, and run loadExtSWF.startLoad, then the external swf is loaded and displayed.

It seems that the way I initially do it, loads the swf to the wrong stage (?).

Any ideas? Thanks for the help.

Bye, RaamEE

P.S.

If you replace the document class for test_tsscreen from test_tsscreen.as to TSScreen.as, and remove the comment inside the test_tsscreen's constructor, the swf will be loaded.

my code is:

file test_as3.swf

an external as3 swf file.

file test_tsscreen.fla

the fla is empty and references test_tsscreen.as as its document class.

file test_tsscreen.as

package {

import flash.display.MovieClip; import TSScreen;

public class test_tsscreen extends MovieClip{ var tsScreen1;

public function test_tsscreen(){ // var tsScreen1:TSScreen = new TSScreen(10,10,100,100,0.5,0); var tsScreen1:TSScreen = new TSScreen(); tsScreen1.startLoad(this.stage); } } }

file TSScreen.as

package { import flash.display.MovieClip;

import flash.display.*; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext;

import flash.display.Loader; import flash.events.Event; import flash.events.ProgressEvent;

public class TSScreen extends MovieClip implements ITSScreenable{

public function TSScreen():void{ // startLoad(this); //Look important comment in above text }

function startLoad(_this:Stage) { var mLoader:Loader = new Loader(); var mRequest:URLRequest = new URLRequest("test_as3.swf");

mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler); _this.parent.addChild(mLoader); mLoader.load(mRequest); trace(this.name); trace(_this.name); }

function onCompleteHandler(loadEvent:Event) { addChild(loadEvent.currentTarget.content); }

function onProgressHandler(mProgress:ProgressEvent) { var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal; trace(percent); }

} }

© Stack Overflow or respective owner

Related posts about as3

Related posts about load