0

Why this works on flash professional's debugger, but brings null on the compiled SWF?

var firstParameter:SomeObject = new SomeObject();
someLoader = new Loader();
someLoader.contentLoaderInfo.addEventListener(
    Event.COMPLETE
  , function(evt) {
      onLoaded(evt, firstParameter);
    }
  , false
);

function onLoaded (evt:Event, param:SomeObject):void {
    mcOnSceneForTracing.text = param; // this is used for SWF debugging
}

For the record:

  • To make it work without any issues this can be "solved" by creating a separate scope. However, here I'm wondering why, then, this example even works on the debugger at least.
  • And, please, if you have a better way other than using two anonymous functions to pass parameters, variables, values, whatever through an Event, do tell! I'm not willing to extend the Event, tho. Too 2005.
  • mcOnSceneForTracing is what I'm using to "trace" outside the debugger. Suggestions are also accepted here for better (and simpler) ways to do it! I've heard Vizzy is good, but haven't tried it yet.
Community
  • 1
  • 1
cregox
  • 17,674
  • 15
  • 85
  • 116
  • The compiled swf should be the same, unless you explicitly remove all debugging code from the "final" version. It is only played in a different version of the Flash player. If the two behave differently, and since you are dealing with a loader event, I assume it is due to timing, and where you've set your breakpoints. To help figure out how to solve your problem, you should provide some more information: What are you trying to accomplish with this piece of code, why would you pass parameters "through the event" instead of having variables to access elsewhere, what exactly "brings null"? – weltraumpirat Jun 14 '11 at 21:01
  • @weltraumpirat first things first! don't you have a simpler nickname? :P ok, ok... I'm trying to load URLs and images from URLs. And "someTxtObjectOnScene" is showing null, I thought it would be obvious enough I was using it for debug, but I can see why it's not (so obvious), so I'll edit that part. Anyway, thanks for trying to "solve my problem", but that's not needed. As I said it is already solved somehow. I'm just wondering why that happened. So don't really matter why I did it, just that the bug is there. – cregox Jun 14 '11 at 21:06
  • The nick is quite simple, just not in your language ;) The reason why I was asking: Obviously you are loading something, but why pass a second parameter along with the event, unless it is something directly related to the outcome of the loading operation itself? – weltraumpirat Jun 14 '11 at 21:17
  • Well, than the language in which you're written is quite complicated! And I never considered loading time would influence the outcome in this scenario, but you're probably right. Very nice! :) – cregox Jun 14 '11 at 21:28

1 Answers1

1

My guess would be: When loading your resource from the debugger player, the operation finishes instantly, and thus firstParameter is available when your anonymous listener function is called, but when running the swf elsewhere, the load operation takes longer, and then the reference to firstParameter is lost, since it is a local variable.

weltraumpirat
  • 22,544
  • 5
  • 40
  • 54