views:

1928

answers:

5

I have a Flash app made up of AS3 components that I am trying to run in Flex.

In Flash, after the main component is added to the stage, the loader object (loaderInfo.loader) is null which is fine and I handle that.

In Flex, on the applicationComplete event I add the the main component to the stage and the loader object's getter throws an exception - Error #2099: The loading object is not sufficiently loaded to provide this information.

Also, the INIT event, which is dispatched when the properties and methods of a loaded SWF file are accessible, is not firing which is probably part of the problem. But I can't figure out why it is not being dispatched.

Any ideas why the same code has two different results?

A: 

Mmm, that seems like a frustrating problem. When you say "main component", I presume you mean the document class in Flash?

I'm not sufficiently knowledgeable about flex to comment on the problem you described, but I can suggest that you try using ADDED_TO_STAGE instead of INIT as your event...

public class MainFlashClass extends Sprite {
  public function MainFlashClass() {
    addEventListener(Event.ADDED_TO_STAGE, onInit);
  }
  public function onInit(e:Event):void {
    removeEventListener(Event.ADDED_TO_STAGE, onInit);

    // do your initialisation code here
  }
}

This might work for both scenarios. I've found ADDED_TO_STAGE to be more helpful because it always gets fired, whether the class is already loaded when the swf is executed (like the document class), or if it's being loaded with a Loader.

aaaidan
A: 

I do process the ADDED_TO_STAGE event. That gets things going.

But the INIT event is different. That tells your code that all the properties of the loader object (loaderInfo.loader) are now initialized. This event is supposed to is fire sometime after the ADDED_TO_STAGE event, but it never fires.

When my code tries to access a property of the loader object, an exception is thrown.

There is something about the Flex start up sequence that is slightly different than Flash.

should be a comment, not an answer
euge1979
(-1) Likewise...
Eran Betzalel
A: 

I'm not sure if this is what's going on with INIT event, but I do know that in flash player 9, which I'm assuming is the version of your SWF? There's a bug with referencing the loader through its own evt target. Basically if you are loading something and you try and access properties of the loader though evt.target.loaderInfo.loader it never can find itself and throws the error you described in your question. I believe it's a known bug for flash player 9 that was fixed with the release of CS4 and flash player 10.

Here's a link to a thread describing some of the problem, hopefully it helps

http://www.actionscript.org/forums/showthread.php3?t=137599

vanhornRF
A: 

Hmmm... Interesting thought... I have Flash Player 10 installed. I wonder if it's a Flex 3 / Flash Player 10 compatibility issue? I'll look into this now. Thanks!

should be a comment, not an answer
euge1979
(-1) Likewise...
Eran Betzalel
A: 

You definitely need to post code so we an see better.

With that said, after addChild are you attempting to grab the loaderInfo for the "main component" or for your mx:Application?

Pseudo

//onApplicationComplete event handler var myswf:SWFLoader = new SWFLoader(); myswf.load(...); addChild(nmyswf);

trace(myswf.loaderInfo.loader); //end onApplicationComplete

Is that what you're doing? If so, you need to add an event listener to your "main component" (assuming an externally loaded swf) to find out when Event.COMPLETE happens.

var myswf:SWFLoader = new SWFLoader(); myswf.addEventListener(Event.COMPLETE, onMySWFComplete); //..rest of code

Hope that helps. If not, post code.

johncblandii