TwelvestoneFront End

strange javascript problem


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
persist
 
2010-06-21

I am trying to wedge a javascript class in place of a flash class into a large application framework. I cannot change the controller code. The javascript class needs to inform the controller when it exists. This is in place of instantiating a swf instance and getting a signal from the Flash externalInterface object that it exists. This event kicks off an init to load data in Javascript.

The problem is porting the Flash ready event to a Javascript constructor looks like:

Shell = function(params){ //this is the constructor console.log("javascript version of the flash!"); var o = {} o.readyState = "ready"; o.payload = {}; this.callEvent(o); }

chartShell.prototype.callEvent = function(obj){ //this function is emulating the externalInterface in flash windowthis.ctrlr; }

Unfortunately, since the event is in the constructor, it fires before the object is available to the document window. Code in the controller fires asking the class for getters. But the class doesn't officially exist yet and it throws errors.

Currently, pathetically, I am doing this:

Shell = function(params){ console.log("javascript version of the flash!"); var scope = this; setTimeout(function(){scope.callInitialized();}, 250); } chartShell.prototype.callEvent = function(obj){ windowthis.ctrlr; }

chartShell.prototype.callInitialized = function (){ var o = {} o.readyState = "ready"; o.payload = {}; this.callEvent(o); }

Am I being dumb? Is there a way to kick off an event from a JS class to let the document know its actually ready and available without a timer?

poliguin
 
2010-06-21

question: are you doing something like this:

var Shell = function(params){ //this is the constructor console.log("javascript version of the flash!"); var o = {} o.readyState = "ready"; o.payload = {}; this.callEvent(o); }

var chartShell = new Shell({}); chartShell.prototype.callEvent = function(obj){ //this function is emulating the externalInterface in flash windowthis.ctrlr; }

and then you are wanting the callEvent to happen as soon as the prototype is created for chartShell?

persist
 
2010-06-21

This is what needs to fire:

var listener = function(e){ if(e.readyState == "ready"){ //j is undefined j.loadData(); } }

var j = new Shell();

It was constructed like this because we had to wait for a swf to load before calling j.load() where j was the swf instance.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFront End

strange javascript problem