External swf loaded into Adobe Air does not get displayed properly

You need to be careful between SWFLoader, Loader, ModuleLoader, MovieClipSWFLoader and read their documentation.





1 Like

When you have a main application which has many sub-apps that you want to load independently it is best practices to use the ModuleLoader inside of the main application and use the Module components in each of your shell.

@duanga.yanga, what you did works. Verified that. However as a side effect, when I start the Shell1.swf directly, now the label and all other stuff is not visible. But when loaded from Main.swf, it works great.
Still, is it not possible to work this out without changing Shell1.mxml ?
I did go througth all the documentation that you put links for.

Also “I understand that changing shell.mxml is trivial. But right now, in the dummy app, its getting downloaded from file system. However in actually, it resides on server and I cannot edit it. Hence I was insisting. Sorry, i didn’t share it before.”

A module cannot be executed as itself you need to rename it as <s:Application>
A module needs a host.

Then you need to try with one each of the different loaders I referred to to understand how the process is differing.

what you can do is once the SWF(with Loader) is loaded you can change the width,percentWidth or height,percentHeight of the content to check if it can fix your problem.

Here are some detailed explanation : https://helpx.adobe.com/flash/kb/load-external-swf-swf.html

I think I found your problem try this:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
		<!-- Place non-visual elements (e.g., services, value objects) here -->
		import mx.controls.SWFLoader;
		import mx.events.FlexEvent;
		import mx.events.ResizeEvent;
		import mx.rpc.events.FaultEvent;
		import mx.rpc.events.ResultEvent;
		private var moduleLoader:SWFLoader;
		private function OnResultHttpService(event:ResultEvent):void {
		private function OnFaultHttpService(event:FaultEvent):void {
		private function loaded(event:Event):void {
			trace("moduleLoader.content.width " + moduleLoader.content.width);
			trace("moduleLoader.content.height " + moduleLoader.content.height);
			moduleLoader.removeEventListener(Event.COMPLETE, loaded);
			//            object.width = 1200;
			//            object.height = 800;
			//            object.visible = true;
		protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
			moduleLoader = new SWFLoader()
			var urlre:URLRequest = new URLRequest("Shell1.swf");
			moduleLoader.addEventListener(Event.COMPLETE, loaded);
		protected function windowedapplication1_resizeHandler(event:ResizeEvent):void
	<s:Group id="container" width="100%" height="100%" />

really all those messages for that?

don’t do this

var ldr:Loader = new Loader();
var url:String = “http://localhost:8080/aps/Shell.swf”;
var urlReq:URLRequest = new URLRequest(url);

don’t load from a localhost

take the sources of your shell.swf and make it an AIR app

@aditya_bajaj just ignore that bully he thinks he is someone better. He is either judgmental or doesn’t care about what is your level of understanding of your problem and will come up with some kind of irrelevant solution. He doesn’t understand the concept of pedagogy.

yeah I forgot for a minute that @duanga.yanga is @gdeverlant
and off course from the last thread here

yeah off course this guy is all about bringing chaos to this forum

OK then 2 things, bye bye @duanga.yanga you’re banned
and your unhelpful advises are not needed anyway

and so 2nd thing ,

you have a Shell.swf which is the root of your Flex app
you’re wasting your time trying to load it as if it was a module
it would be faster to edit the sources and make it an AIR app

and what is an AIR app?, it is SWF associated to an app xml
so yeah you can have both a main SWF that is a Flex app and that is an AIR app

so now instead of using an HTML container to load that Shell.swf
you will simply use an AIR NativeWindow class

read the docs
Basics of native windows in AIR
Flex WindowedApplication class

The WindowedApplication defines the application container that you use to create Flex applications for AIR applications.

The WindowedApplication serves two roles. It is a replacement for the <mx:WindowedApplication> tag, functioning as the entry point to a Flex-based AIR application. In addition, as a container the WindowedApplication defines the layout of the initial window of a Flex AIR application – any visual controls defined in the WindowedApplication become the content of the initial window loaded by the AIR application.

A WindowedApplication is the top-level application of a Flex-based AIR application. It is not designed to be loaded by other Flex applications. If a WindowedApplication needs to load other applications, use the Application class as container for those applications. If other windows are required, use the Window class as a container for those windows.

and yes you have to change the code of Shell.swf because you want to change the container

and if you bothered to look at the doc I pointed earlier you would have found that

Developing AIR applications with Flex Builder 3

Creating your first desktop Flex AIR application in Flash Builder

and yes you will have to merge your Flex SDK with the AIR SDK
again in the docs Adobe Flash Platform tools for AIR development

the official doc for Flex is there

in Chapter 2: Getting Started

Compiling MXML to SWF Files

If you are using Flash Builder, you compile and run the compiled SWF file from within Flash Builder. After your application executes correctly, you deploy it by copying it to a directory on your web server or application server.

You can deploy your application as a compiled SWF file, as a SWF file included in an AIR application or, if you have Adobe LiveCycle Data Services ES, you can deploy your application as a set of MXML and AS files.

you can also find
Developing AIR applications with Flex (web archive, not sure if it got all the content)

or here on O’Reilly
Developing AIR applications with Flex
and Safari books
Developing AIR applications with Flex

I have already converted the flex application to AIR application. I wanted to further generalize it to be able to load any swf file from remote server. Hence the effort. Also, after going through the documentation, I am somewhat confident that the above problem could not be solved without making any change to remote swf. I had to mention height and width in pixels in remote flex application and then load it using swfLoader and it worked.