Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411910 Posts in 69430 Topics- by 58477 Members - Latest Member: KriegsHetzer

June 10, 2024, 03:53:31 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Loading an SWF
Pages: [1]
Print
Author Topic: Loading an SWF  (Read 1464 times)
agj
Level 10
*****



View Profile WWW
« on: March 20, 2010, 09:53:26 PM »

I have something planned for The Games Collective bricolage pageant, but I've ran into a problem. Is there a way to load a Flash game in SWF form into Flash without there being issues? I believe that these are related to the preloader in the loaded game, since it means that it starts running before it is fully loaded and put on the stage.

My code:

Code:
	public class Main extends Sprite {

public function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point

var loader:Loader = new Loader;
var request:URLRequest = new URLRequest("viewpoints.swf");

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(request);
}

private function onLoaded(e:Event):void {
addChild(e.currentTarget.content);
}
}

And the error thrown is:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at perspective3_fla::MainTimeline().


perspective3_fla is the loaded game, not this one. It errors before the 'complete' event is triggered, too.

Is there a way around this?
Logged

bateleur
Level 10
*****



View Profile
« Reply #1 on: March 21, 2010, 01:26:05 AM »

How much do you know about the loaded SWF? Is it your own code?

Problems can be caused by things like the loaded SWF being written in AS2 when you're using AS3 and/or making assumptions about things like whether it's running directly at _root, whether it's on the Stage when it starts (you appear to be loading offstage, so this could be your problem) and what the timings are between various things (badly written SWFs sometimes require their own loading delays).
Logged

agj
Level 10
*****



View Profile WWW
« Reply #2 on: March 21, 2010, 05:14:00 PM »

It's mine, yup. I did make the assumption that it was being loaded on the stage, of course. But this is what I want to sidestep somehow, as I don't want to recompile the original code, because the concept for what I'm trying to do requires it. I'd like to know if there's a way to load the SWF without triggering the preloader, somehow, before I put the thing on the stage. Or something else that would achieve the same effect, but from the loader side.
Logged

jotapeh
Level 10
*****


View Profile
« Reply #3 on: March 22, 2010, 08:06:50 AM »

Is your loaded SWF trying to access the stage? eg., setting stage.align = StageAlign.TOP_LEFT or something?
Logged
agj
Level 10
*****



View Profile WWW
« Reply #4 on: March 22, 2010, 08:39:44 AM »

Probably; I don't quite remember. I guess it's likely.
Logged

bateleur
Level 10
*****



View Profile
« Reply #5 on: March 22, 2010, 09:35:21 AM »

I'd like to know if there's a way to load the SWF without triggering the preloader, somehow, before I put the thing on the stage. Or something else that would achieve the same effect, but from the loader side.

The short answer is: no.

However, there is a slight possibility that you can hack your way around the problem by loading onstage but with the entire loading SWF hidden behind something so the user can't tell. I hope your preloader doesn't make any sounds! Cheesy
Logged

agj
Level 10
*****



View Profile WWW
« Reply #6 on: March 22, 2010, 02:19:28 PM »

Oh, I don't have a problem with the preloader showing. The problem is that it is triggered before I can even place it on the stage, therefore causing the problems I mentioned.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic