-2

I've read through posts on "SWF loading issues" on many sites and nothing helps. Maybe my environment or some tiny thing missed causing LOADER.CONTENT to always be NULL. The SWF files are in the same FOLDER which is added to the TRUSTED LOCATIONS in Flash Preferences.

I'm using mxmlc -static-link-runtime-shared-libraries to build both SWF files, one is the main, the other is the assets "images, sounds, and some code". LOADER.PROGRESS is getting triggered: EVENT.bytesLoaded quickly equals EVENT.bytesTotal "11303918", but all CONTENT elements are NULL, thus no CLASS to attach. I have given up on LOADER.COMPLETE, because it never triggers locally, some say it's a FIREFOX caching issue; thus, I am just triggering completion through PROGRESS bytes.

To protect the innocent some names have been changed "MAIN, PART, and ASSETS", but no code has been harmed in the writing of this post... yet.

10952  MAIN.swf - includes PART.as and MAIN.as
11303918  ASSETS.swf - includes ASSETS.as only

My Flash App is a simple music mixer. The Main defines the control board. The Assets provide the Music, Images, and some executable code.

All works fine if built as a single SWF. I want to add a preloader because some devices like cell-phones, load very slowly and preloaders are so entertaining. Thus, Assets have been placed in their own SWF to be loaded by the Main.

Here are the important parts of my code: No compiler errors, so assume all imports exist and variables defined.

MAIN.as -- MAIN.SWF

package { ...
    [SWF(scaleMode="noScale", widthPercent="100%", heightPercent="100%", frameRate="20", backgroundColor="#000000")]
public class MAIN extends Sprite { ...
function MAIN():void {
    if( stage ) { MAINInit(null); return; }
    addEventListener(Event.ADDED_TO_STAGE,MAINInit);
    }
private function MAINInit(e:Event):void {
    if( e ) { removeEventListener(Event.ADDED_TO_STAGE,MAINInit); }
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align     = StageAlign.TOP_LEFT;
    w=stage.stageWidth; h=stage.stageHeight;
    part=new PART(w,h,loadMSG,assetsComplete);
    }
private function assetsComplete():void {...
}}}

PART.as -- SWC built into MAIN.SWF

package PART { ...
public class PART { ...
    private static var stuffLoader:Loader=null;
    private static var STUFFCLASS:Class=null;
    public static var STUFF:*=null;
public function PART(w:int,h:int,msg:TextField,cb:Function):void { ...
    if( !stuffLoader ) {
        var stuffRequest:URLRequest=new URLRequest("ASSETS.swf");
        var stuffContext:LoaderContext=new LoaderContext(false,ApplicationDomain.currentDomain,null);
        stuffContext.allowCodeImport=true;
        stuffLoader=new Loader();
        stuffLoader.load(stuffRequest,stuffContext);
        stuffLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,stuffLoading);
        //stuffLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,stuffLoaded);
    }}
public static function stuffLoading(e:ProgressEvent):void {
    welcomeBytes=e.bytesLoaded;///1024;
    welcomeTotal=e.bytesTotal;///1024;
    welcome(e.currentTarget);
    }
public static function stuffLoaded(e:Event):void { complete(e.currentTarget); }
public static function complete(target:Object):void { ...
    stuffLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,stuffLoading);
    //stuffLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,stuffLoaded);
    var objectLoaderInfo:LoaderInfo=LoaderInfo(target); 
    var appDomain:ApplicationDomain=objectLoaderInfo.applicationDomain;     
    if( appDomain.hasDefinition("ASSETS")) { ...
        // always false
        }
    else {... 
        stuffLoader.content; // always null
        stuffLoader.contentLoaderInfo.content; // always null
        objectLoaderInfo.content; // always null
        }
    STUFFCLASS=Class(stuffLoader.contentLoaderInfo.applicationDomain.getDefinition("ASSETS")); // always null
    STUFF=new STUFFCLASS(width,height); // crash because NULL reference
    ...
    }
public static function welcome(target:Object):void {
    var pct:int=100*welcomeBytes/welcomeTotal;
    ...
    if( welcomeBytes==welcomeTotal ) { complete(target); }
}}}

ASSETS.as -- ASSETS.SWF

package { ...
public class ASSETS extends Sprite {
    [Embed(source="../Sounds/beep001.mp3")] private static var SNDCLSbeep001:Class;
    private static var SNDbeep001:Sound=new SNDCLSbeep001() as Sound;
    ...
function ASSETS(w:int,h:int):void {...
    }
public function background(w:int,h:int):void {...
}}}

At the end of my rope. The loader.progress loads the bytes, but every CONTENT is null, thus no hook to convert to CLASS and access ASSETS embedded therein.

  • The problem is looking more and more like a security issue. I uploaded the governing HTML that embeds the MAIN.swf which then attempts to load ASSETS.swf internally to my website and got the same results as run locally. All three files are located in the same spot. The contentLoaderInfo.loaderURL is set, however contentLoaderInfo.url is NULL along with isURLInaccessible set TRUE. How do I makes these two SWF's communicate? All code is as shown above. Will keep digging into security path. – OstrichEyes.com Jan 07 '16 at 22:59
  • Problem was in ASSETS.SWF constructor. As a built in library, ok to have parameters. But after converting from SWC to SWF, the loader will call without parameters to innitiate class and run any system stuff like `Security.allowDomain()`. Leaving in the coded params caused the constructor to pop two arguments that were never pushed and thus the loader crashed and could not complete the load. Simply creating a separate init method allowed the `EVENT.COMPLETE` to get triggered, and life is good. If you'd like to try the music mixer it can be found on OstrichEyes.com, Chakras Composer 3. – OstrichEyes.com Jan 09 '16 at 18:18

1 Answers1

0

Problem solved in comments, code change minor as follows.

Package {
public class ASSETS extends Sprite {
    function ASSETS():void { . . .
        }
    public function init(w:int,h:int):void { . . .
}}}

Breaking out width and height params into separate initialization method.