That looks about the right amount of code to me.  Someday, I expect AIR to make 
this easier, but I wouldn't hold my breath waiting.

Alex Harui
Flex SDK Developer
Adobe Systems Inc.<http://www.adobe.com/>
Blog: http://blogs.adobe.com/aharui

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of handitan
Sent: Friday, October 09, 2009 8:33 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: ADOBE AIR Qs: How do you load modules from 
"app-storage" domain?



Hi Alex!

Good to hear from you.
And yes, you're right! I got it to work but there's so much code involved just 
to get this module loaded.
Gosh...I wonder if I am in the right direction or not...

This code is basically based on "Hai Nguyen" example from eSoftHead with little 
modification (Thx Hai!).
Here's the code if anyone is interested:
<mx:WindowedApplication>
<mx:Script>
private function loadSwf():void
{
var dir:File = File.applicationStorageDirectory
dir = dir.resolvePath("SimpleSwf.swf");//SimpleSwf is the
module

var myURLRequest:URLRequest = new URLRequest(dir.url);
var myURLLoader:URLLoader = new URLLoader();
myURLLoader.dataFormat = URLLoaderDataFormat.BINARY;
myURLLoader.load(myURLRequest);

myURLLoader.addEventListener(Event.COMPLETE,loadModuleCompleteHandler);
}

private function loadModuleCompleteHandler(pEvent:Event):void
{
var context:LoaderContext = new LoaderContext();
context.allowLoadBytesCodeExecution = true;
context.applicationDomain = ApplicationDomain.currentDomain;

var moduleLoader:Loader = new Loader();
var loader:URLLoader = URLLoader(pEvent.target);
moduleLoader.loadBytes(loader.data,context);
moduleLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeLoader);
}

private function completeLoader(e:Event): void {
var moduleLoader:LoaderInfo = LoaderInfo(e.target);
moduleLoader.content.addEventListener("ready", readyHandler);
}

private function readyHandler(e:Event): void {
var factory:IFlexModuleFactory = IFlexModuleFactory(e.target);
var module:Module = factory.create() as Module;
container.addChild(module);

}
</mx:Script>

<mx:VBox width="100%" height="100%">
<mx:Button label="Load SWF" click="loadSwf()"/>
<mx:VBox id="container"/>
</mx:VBox>
</mx:WindowedApplication>

--- In flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>, Alex 
Harui <aha...@...> wrote:
>
> I'm not sure what moduleLoader is. You should be using IModuleInfo.load().
>
> Then, a UIComponent makes a poor container. It doesn't know how to measure or 
> layout the child so the child might have 0 size.
>
> Alex Harui
> Flex SDK Developer
> Adobe Systems Inc.<http://www.adobe.com/>
> Blog: http://blogs.adobe.com/aharui
>
> From: flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com> 
> [mailto:flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>] On 
> Behalf Of handitan
> Sent: Thursday, October 08, 2009 8:03 PM
> To: flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>
> Subject: [flexcoders] ADOBE AIR Qs: How do you load modules from 
> "app-storage" domain?
>
>
>
> Hi all,
>
> I am using AIR 1.5 SDK.
> I am trying to find a way to build patching mechanism for my AIR app, which 
> consists modules, sqlite DBs, and other files, by updating ONLY files that 
> need to be updated.
>
> I know that this is not possible using AIR Update Framework because the way I 
> understand it works is that any update that you have both minor and major, 
> you will have to reinstall everything. This is a pain if you have a huge size 
> AIR app.
>
> I have sort of an idea to build my own update mechanism but in order for this 
> to work, I will need to be able to do update operation on my AIR app files.
>
> Since "app" domain doesn't allow us to do that, I have to find a place where 
> updates can take place and my app could still work. I read that "app-storage" 
> allows you to do all of that.
>
> Okay... so I build a really simple AIR app that the sole purpose is to load 
> swf module from "app-storage" to prove my theory.
>
> So here's my AIR app code the short version:
>
> <mx:WindowedApplication>
> <mx:Script>
> private function loadSwf():void
> {
> var dir:File = File.applicationStorageDirectory
> dir = dir.resolvePath("SimpleSwf.swf");//SimpleSwf is the module
>
> var myURLRequest:URLRequest = new URLRequest(dir.url);
> var myURLLoader:URLLoader = new URLLoader();
> myURLLoader.dataFormat = URLLoaderDataFormat.BINARY;
> myURLLoader.load(myURLRequest);
> myURLLoader.addEventListener(Event.COMPLETE,loadModuleCompleteHandler);
> }
>
> private function loadModuleCompleteHandler(pEvent:Event):void
> {
> var context:LoaderContext = new LoaderContext();
> context.allowLoadBytesCodeExecution = true;
> context.applicationDomain = ApplicationDomain.currentDomain;
>
> var moduleLoader:Loader = new Loader();
> var loader:URLLoader = URLLoader(pEvent.target);
> moduleLoader.loadBytes(loader.data,context);
>
> container.addChild(moduleLoader);
> }
> </mx:Script>
>
> <mx:VBox width="100%" height="100%">
> <mx:Button label="Load SWF" click="loadSwf()"/>
> <mx:UIComponent id="container"/>
> </mx:VBox>
> </mx:WindowedApplication>
>
> The result is:
> When I click the button "Load SWF", I could see that the loader loads the SWF 
> correctly (it got the right size, etc) but I didn't see the module shows up 
> on the screen at all.
> I didn't know what I do wrong.
>
> Please enlighten me.
>

Reply via email to