Jump to content
GreenSock

JRockFTW

Loading SWF into itself via SWFLoader

Recommended Posts

I'm attempting to load my main swf into itself.  When I publish the swf via FlashBuilder to Adobe Flash Professional, the SWFLoader loads the swf into itself and dispatches a complete event.  When I double click the resultant published swf from Windows, SWFLoader is not dispatching the complete event.

 

 

Waiting for Player to connect...

[sWF] C:\workspace\Flash\Test\bin-debug\Main.swf - 2795134 bytes after decompression

LOGGER>>Fri Apr 5 13:06:14 GMT-0400 2013::Main

LOGGER>>Fri Apr 5 13:06:14 GMT-0400 2013::addedToStage

LOGGER>>Fri Apr 5 13:06:14 GMT-0400 2013::onLoaderInfoComplete

LOGGER>>Fri Apr 5 13:06:14 GMT-0400 2013::loadXML

LOGGER>>Fri Apr 5 13:06:14 GMT-0400 2013::Loading[C:\TEMP\Data.XML]

LOGGER>>Fri Apr 5 13:06:14 GMT-0400 2013::onStageVideoAvailability[AVAILABLE]

LOGGER>>Fri Apr 5 13:06:14 GMT-0400 2013::*** STAGE VIDEOS AVAILABLE[4] ***

[sWF] C:\TEMP\Main.swf - 2795134 bytes after decompression

 

Even when both 'Main.swf' instances are the same physical file, for example C:\TEMP\Main.swf loads C:\TEMP\Main.swf, it doesn't fire LoaderEvent.COMPLETE.

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

I created a test that works fine on Mac and PC

 

 

 

import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import flash.events.MouseEvent;


var t:SWFLoader = new SWFLoader("loadIntoSelf.swf",{x:50,alpha:1,container:this,onComplete:onComplete});




mc.addEventListener(MouseEvent.CLICK, loadme);
function loadme(e:MouseEvent):void {
t.load();
}


//you can visually see each new load of the swf fading out.
function onComplete(e:LoaderEvent):void {
trace("loaded");
this.alpha=0.5;
}
 

CS5 files attached

 

Please use the latest GreenSock library (not attached). Download via "getGSAP" button above.

 

 

loadIntoSelf_CS5.zip

Link to comment
Share on other sites

VerifyError: Error #1053: Illegal override of onInitTween in com.greensock.plugins.TransformAroundPointPlugin.

Link to comment
Share on other sites

Hi I further verified that there is nothing wrong with using TransformAroundPoint plugin in a swf that loads into itself.

 

Based on the information you provided I can suggest reading this:

http://forums.greensock.com/topic/4199-greensock-for-android-or-ios/#entry23814

 

Hopefully that solves it. 

 

If you continue to have problems please provide a reduced test case so that we can get a better idea of what may be the problem. Your files should only include the minimal amount of assets and code necessary to replicate the problem. Since you are using bonus plugin , TransformAroundPointPlugin, don't include the greensock files. We'll test with the latest version of v12, which you can get from your account page.

 

I'm pretty sure once you ensure that all the swfs in your app are compiled with the same version of the GSAP library you should be fine.

Link to comment
Share on other sites

Thanks for your timely response Carl.  I'll do some sanity checking on my end and report back if I face further issues.  

Link to comment
Share on other sites

Unfortunately, with the latest api it gets as far as 

 

[sWF] C:\TEMP\Main.swf - 2795134 bytes after decompression

 

And that's it, no signs of life after that.  It will be very hard to reduce down to a base case as this is not a small project.  I'll keep fiddling around with it.  I am just unsure as to why it works when launched from Adobe Flash Professional but not launched by a manual double-click.

Link to comment
Share on other sites

Here's the code in question... Pretty basic.  The loaderMax instance has it's load function called outside of the scope of this .as file.

 

override public function loadObjects( loaderMaxQueue:LoaderMax, scaleHelper:ScaleHelper, displayObjectContainer:DisplayObjectContainer = null ):void {

this._loadTime = new Date().time;

this._readyTime = new Date().time;

 

this.scaleHelper = scaleHelper;

this.displayObjectContainer = displayObjectContainer;

 

this.dispatchEvent( new ResourceAddedEvent( this, ResourceAddedEvent.INSETSHOW ) );

this.showXMLPath = showXMLPath;

 

this._swfLoaders = new Vector.<SWFLoader>();

 

var swfLoader:SWFLoader = this.getSWFLoaderInstance();

 

this._swfLoaders.push( swfLoader );

 

loaderMaxQueue.append( swfLoader );

 

this._containerSprite = new Sprite();

}

 

private function getSWFLoaderInstance():SWFLoader {

var swfLoader:SWFLoader = new SWFLoader( "C:\\Temp\\Main.swf", {

bgColor: 0x000000,

width: this.layout.width * scaleHelper.ScaleFactorX,

height: this.layout.height * scaleHelper.ScaleFactorY,

name: "C:\\Temp\\Main.swf",

autoPlay: false,

scaleMode: com.greensock.layout.ScaleMode.STRETCH,

visible: false

});

swfLoader.addEventListener( LoaderEvent.COMPLETE, onLoaderEvent, false, 0, true );

swfLoader.addEventListener( LoaderEvent.ERROR, onLoaderEvent, false, 0, true );

return swfLoader;

}

 

private function onLoaderEvent( loaderEvent:LoaderEvent ):void {

try {

var swfLoader:SWFLoader = loaderEvent.target as SWFLoader;

swfLoader.removeEventListener( LoaderEvent.COMPLETE, onLoaderEvent );

swfLoader.removeEventListener( LoaderEvent.ERROR, onLoaderEvent );

 

this._loadTime = new Date().time - this._loadTime;

 

switch( loaderEvent.type ) {

case LoaderEvent.COMPLETE:

this._containerSprite.addChild( swfLoader.content );

break;

case LoaderEvent.ERROR:

Main.logger.updateLog( loaderEvent.text );

// @todo throw error...

break;

}

this._loaded = true;

} catch( err:Error ) {

trace( err.getStackTrace() );

}

}
Link to comment
Share on other sites

Further information...

 

The loaderMaxQueue reports 98.9% progress, the inner swf doesn't complete and subsequently the loaderMaxQueue also doesn't complete.

Link to comment
Share on other sites

Thanks for doing your due diligence in trying to provide more information.

It seems your setup is touch more complex than my reduced test case ;)

 

I don't know how much more I can assess by just looking at code. It's reassuring that both your code and GreenSock code works as expected from Flash Pro. It is a bit troubling that the stand alone flash player is proving to be problematic, I'm not quite sure how to trouble shoot this particular player. Are you using the latest version of Flash Player? Have you tried different versions? 

 

http://www.adobe.com/support/flashplayer/downloads.html

 

Have you tried other runtime environments?

I would suggest doing a quick embed in an html wrapper to test the browser plugin version of Flash Player and also exporting an exe projector from Flash pro. 

 

Are you getting an errors?

 

I'll kick this issue up the food chain and we'll let you know if we have any more info for you.

 

Please keep us posted on your progress / results.

Link to comment
Share on other sites

I'm curious - why are you loading a swf into itself? Wouldn't that create and endless recursion (unless you're requiring some interaction before the load like Carl did in his example)?

 

 

As far as the different behavior in the standalone player vs. inside the Flash IDE, that kinda smells like a security issue (maybe). I think when you publish inside Flash, it is more permissive security-wise. Did you select the option for allowing "network files only" or "local files only"?

 

I also wonder if your base class for the SWF is something custom because it seems like a tricky thing for Flash to manage ApplicationDomain-wise for Flash to have a certain class do something that then causes it to load a swf that overwrites that very class itself in the ApplicationDomain. Are you using currentDomain or a new one?

 

Like Carl said, in order for us to troubleshoot this effectively, we really need a simplified set of files that we can just crack open and click "publish" and see what's going on (and of coure we'd open it in the standalone player as well). It's just VERY difficult to troubleshoot an issue blind, that's all. You're the only person (at least that I can remember) who has ever mentioned an issue like this, so I'm wondering if it's specific to your setup or if there's something else at play. We'd definitely like to help iron out any issues in LoaderMax if they exist.

Link to comment
Share on other sites

Carl,

 

Yes, I have tried versions 1.4 and 1.6 of the stand alone debug Flash Player thinking it may have been an Adobe update that caused it, but to no avail.

 

Double-clicking the swf simply yielded a black stage so I attached various versions of the stand alone debug Flash Player into remote debug sessions in Adobe Flash Professional and only there was I able to find out how far it was getting in the load process.

 

If I untrust C:\Temp I get a security sandbox exception. But it does fire the complete event with an exception on stage access. But with that folder trusted I get no exceptions or errors, but also no complete event being fired.

 

Jack,

 

The SWF is being used as a rendering engine, driven by an external XML that describes the multimedia resources and paths to the resources to be rendered. The beauty of it is that it can be loaded into itself and be pointed at a different XML to show a window like view of multimedia. There isn't a risk of recursion as it is managed by the application creating the XML.

 

I have published the SWF with access to "local files only" as you mentioned.

 

My main document class is not extending any custom object.

 

I have not specified for the swfLoader to reference a new application domain and I will try that approach next.

 

I am also trying to visual what the easiest way to give you something to work with, as this swf is an engine that relies on several elements working together and my company is very finicky with intellectual property :).

 

Once again, I am truly grateful for the timely support.

Link to comment
Share on other sites

Jack/Carl

 

I added this to my SWFLoader instantiation using the vars.

 

context: new LoaderContext( false, new ApplicationDomain() ),

 

It now appears to be working as expected. This may be something the Adobe Flash IDE is doing for me under the hood.

 

Thanks for getting me in the right direction. Your support has been excellent!

  • Like 2
Link to comment
Share on other sites

Excellent. Glad to hear that got you pointed in the right direction. I appreciate you reporting back too, just in case someone else with the same problem searches the forums in the future. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×