Jump to content
Search Community

Can't get swfs to load...

Vicware test
Moderator Tag

Recommended Posts

I must be missing something. I want to use loaderMax to load some swf's. So I started with a very

simple start up class file that just loads one swf and displays it. When I run it with a very simple

sample file swf it works fine. But any of my swf's, when I run it never completes the load and I get

the error in the ide: (I have a simple progress feedback)

 

progress: 0.9899827010500061

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at sceneMover()

 

When I run this file by itself, it works fine.

 

My swfs, like sceneMover swf above have loadermax stuff in it to load images and text files. I don't

know if that has anything to do with this problem.

 

Again, when I run this file standalone, it works fine.

 

I don't understand how I'm supposed to troubleshoot this when my fla/swf's work fine standalone. Here is the basic

code for loading this particular swf:

 

public function collectSWFs():void {

var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

queue.append( new SWFLoader("source/sceneflip/SceneFlipper.swf", {name:"sflip", estimatedBytes:46000, container:this, x:250, autoPlay:true}) );

 

queue.load();

}

 

Again, I tried a simple demo swf instead of SceneFlipper.swf, and it works fine - just not my swf.

 

Can you give some clue what this could be about please?

 

Vic

Link to comment
Share on other sites

The problem doesn't sound related to LoaderMax - can you post your sceneMover() method? That's where the error is being thrown. I wonder if you're trying to access the "stage" inside sceneMover() but it is null until that swf is actually added to the stage. That has nothing to do with LoaderMax - that's just a Flash thing. For example, if you have this in your document class's constructor:

 

this.stage.addEventListener(MouseEvent.CLICK, clickHandler);

 

It'll work fine when you run it standalone. But if you subload that swf it will throw errors because this.stage is always null until the object is in the display list. The solution would be to either make sure you define a "container" in your SWFLoader or add code to your sub-swf that correctly handles a situation where this.stage is null, like:

if (this.stage == null) {
   this.addEventListener(Event.ADDED_TO_STAGE, init);
} else {
   init(null);
}

function init(event:Event=null):void {
   this.removeEventListener(Event.ADDED_TO_STAGE, init);
   this.stage.addEventListener(MouseEvent.CLICK, clickHandler);
   ...
}

 

If that doesn't help, feel free to post an FLA that clearly demonstrates the issue (the simpler the better).

Link to comment
Share on other sites

Well, you had that close to the mark. I have it now completing the load:

 

progress: 0.9899949773982923

progress: 1

LoaderMax 'mainQueue' is complete!

 

If I might ask you one more question since I hardly ask for help, but loading swfs into swfs is a

new process for me. I'm confused now because the files that the sub-swf goes to load is going to

the wrong path to find files, so my first error (my main xml file) after the successfull load is:

 

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///E|/Projects/MainSite/flipList.xml

at sceneMover()

 

But the sceneMover swf is in MainSite/souces/sceneflipper/.

Even though flipList.xml is in the same folder as the imported swf, and that swf refers to that xml file, the

root fla/swf is making the sub-swf look in the root folder of the main class instead of in the same folder

as the imported swf.

 

I know I could add the paths, or use ../ , (or your prepend), etc., but the process is that I work on these different swfs that

will end up being loaded by my root swf, but in the meantime I should be able to make changes to the

sub-swf and test, and then copy that swf to my MainSite/source folder.

 

Is there a way for a loaded class to know what it's pathname is so I can do this algorymically? Maybe you

know a good url that covers this.

 

Thanks again -

Vic

Link to comment
Share on other sites

Yeah, that's just how Flash works - all relative paths are interpreted as relative to the base (root) swf's location.

 

There are many ways you could approach this with code. Here are a few ideas off the top of my head:

 

1) To discover if the swf is being subloaded, you could do something like this in the document class or on the first frame:

if (this.parent != null && this.parent == this.stage) {
  //not being subloaded
} else {
  //is being subloaded
}

 

2) To discover if the swf is being subloaded specifically by LoaderMax's SWFLoader (not that you need to), you could recursively loop through the parent DisplayObjectContainers and see if any are ContentDisplay objects. If so, you know you're being subloaded by a SWFLoader.

 

3) Use the alternateURL feature of LoaderMax to define...um...alternate URLs. So the main ones would be for when you're subloading and the alternate ones might be for when you're not subloading. That way it'll work either way (although you'll pay a slight speed price when the first URLs fail and switch to the alternate URLs).

 

There are more ways to approach it, but hopefully this gives you a few ideas.

Link to comment
Share on other sites

thanks - usefull info. For the moment, I constructed subfolders in the development folder

mirroring what the compilation path looks like. But I will try to do something a little

more elegant.

 

On another note: http://www.vicware.com/mainsite/vicware1.html

 

I'm now seeing that there are interruptions between 2 different swfs put together

in this way. You'll see Max-transitions that slow down processing in the other (atom)

swf. Also, perspectiveprojection that looks good in the standalone version is very

different in the combined version (flipper board). oy, what a mess. AS3 will kill me

yet.

 

Vic

Link to comment
Share on other sites

i don't have problem loading multiple swf (in my case i load 20 swf). Maybe u want to share ur source code?

 

private static var loaderName:String = "MainMenu";
private static var _sound_Music1:String = "sound_Music1";

public function scene_MainMenu()
{
//var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler}); 
queue = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler}); 
queue.append( new SWFLoader("resources/MainMenu.swf", { name:loaderName } ) );
queue.append( new MP3Loader("resources/music1.mp3", {name:_sound_Music1, autoPlay:false}) );
queue.load();
}

private function completeHandler(event:LoaderEvent):void {			
var image:ContentDisplay = LoaderMax.getContent(loaderName);
addChild(image);

image.addEventListener(MouseEvent.CLICK, onButtonClick);

aDynamicObject_Sound[string(_sound_Music1)] = new Sound();
aDynamicObject_Sound[string(_sound_Music1)] = Sound(retrieve_Content(_sound_Music1));
aDynamicObject_SoundChannel[string(_sound_Music1)] = new SoundChannel();
aDynamicObject_SoundChannel[string(_sound_Music1)] = aDynamicObject_Sound[string(_sound_Music1)].play(0, 2);

var _event:Event = new CustomEvent(Event.COMPLETE);
dispatchEvent(_event);
}

public function retrieve_Content(tmpStr:String):Object
{
return LoaderMax.getContent(tmpStr);
}



Link to comment
Share on other sites

Well, what I was saying was the graphic performance of the 2 individual swf's running side by side

was not great - not anything about loading performance. I have similiar code for loading:

 

public class collectSWFs extends MovieClip {

private var sContain:MovieClip = new MovieClip();

private var aContain:MovieClip = new MovieClip();

 

public function collectSWFs():void {

var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

 

queue.append( new SWFLoader("source/atom/atom03.swf", {name:"atom", estimatedBytes:120000, container:aContain, x:6, y:2, autoPlay:true}) );

queue.append( new SWFLoader("source/sceneflip/SceneFlipper.swf", {name:"flip", estimatedBytes:46000, container:sContain, x:230, y:0, autoPlay:true}) );

 

queue.load();

}

 

function progressHandler(event:LoaderEvent):void {

trace("progress: " + event.target.progress);

}

 

function completeHandler(event:LoaderEvent):void {

addChild(aContain); addChild(sContain);

}

 

function errorHandler(event:LoaderEvent):void {

trace("error occured with " + event.target + ": " + event.text);

}

 

Or the loader for the flipper images:

 

private function ImageInit():void {

var queueImage:LoaderMax = new LoaderMax({name:"imageQueue", maxConnections:3, estimatedBytes:60000, onProgress:progressHandler, onComplete:completeImages, onError:errorHandler});

for(var imgCnt:int = 0, imglen:int = shortBMArray.length; imgCnt < imglen; imgCnt++) {

queueImage.append(new ImageLoader(shortBMArray[imgCnt], {name:shortBMArray[imgCnt], alpha:1, width:510, height:225, centerRegistration:true, onComplete:completeFirstImg}) );

}

queueImage.prependURLs("source/sceneflip/");

queueImage.load();

}

 

I probably need to re-write the atom swf - it was done a year ago with Away3D - 120k swf for just that.

 

Like I said - it's a mess. Thank you very much for your input and any other suggestions.

 

Vic

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.
×
×
  • Create New...