Deepak
Deepak

Reputation: 1258

Loading An External Interactive swf in Air Mobile

I am trying to learn ActionScript 3 for the purpose of using the Air for Mobile ( Android ) feature. I have two swf files and would like to load and run the second file from the first file. This works fine when i package both files as part of the apk.

But if the second swf file is placed in user storage the file is loaded but it does not wait for user interaction.The swf plays out like a video.

This is what i wrote in the first file to load the second file.

var loader:Loader=new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("file:///storage/emulated/0/swfs/second.swf"));

function onLoaded(e:Event):void
{
    addChild(loader);
}

I would really appreciate it if some one can point me i the right direction.

This the code in second.swf. Event though now i can see the button.. the click event does not work. Now i am not sure this issue is totally related to AS3.

loader.contentLoaderInfo.addEventListener(Event.ENTER_FRAME, handleReady );
function handleReady( initEvent:Event ):void
{
    trace("Enter-Frame");
    MovieClip(initEvent.currentTarget.content).stop();
}

button.addEventListener(MouseEvent.CLICK,touchfun);
function touchfun(e:MouseEvent)
{
    trace("btn click");
    button.visible=false;
} 

Upvotes: 1

Views: 975

Answers (1)

Wary Warcry
Wary Warcry

Reputation: 93

You should set "allowCodeImport" to true in the first swf which loads the second one. First you need a context object to set the flag;

var context:LoaderContext = new LoaderContext();
context.allowCodeImport = true;

Then you should pass this context object to your loader;

var loader:Loader=new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("file:///storage/emulated/0/swfs/second.swf"), context);

function onLoaded(e:Event):void
{
    addChild(loader);
}

Upvotes: 3

Related Questions