Javascript to Flash & Firefox

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

I can't for the life of me get a Flash movie to respond to Javascript in Firefox 2.

I've tried using a variable in _root
Code: [ Select ]
var myVar:Number;

Watching that variable
Code: [ Select ]
var callB:Function = function(prop, newval, oldval):Number {
  doSomthingWithNewval(parseInt(newval));
  return parseInt(newval);
}
this.watch("myVar", callB);
  1. var callB:Function = function(prop, newval, oldval):Number {
  2.   doSomthingWithNewval(parseInt(newval));
  3.   return parseInt(newval);
  4. }
  5. this.watch("myVar", callB);


Using setVariable in JS
Code: [ Select ]
function getSWF(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  }
  else {
    return document[movieName];
  }
}
getSWF('myMovie').setVariable('myVar', '0x123456');
  1. function getSWF(movieName) {
  2.   if (navigator.appName.indexOf("Microsoft") != -1) {
  3.     return window[movieName];
  4.   }
  5.   else {
  6.     return document[movieName];
  7.   }
  8. }
  9. getSWF('myMovie').setVariable('myVar', '0x123456');


That works in Internet Explorer.

I've tried using "mx.external.ExternalInterface.addCallback"
Code: [ Select ]
var callB:Function = function(par):Void {
  // Stuff
}
ExternalInterface.addCallback("swfSetTheme", null, callB);
  1. var callB:Function = function(par):Void {
  2.   // Stuff
  3. }
  4. ExternalInterface.addCallback("swfSetTheme", null, callB);

Calling the registered method with JS
Code: [ Select ]
function getSWF(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  }
  else {
    return document[movieName];
  }
}
getSWF('myMovie').swfSetTheme(myVar);
  1. function getSWF(movieName) {
  2.   if (navigator.appName.indexOf("Microsoft") != -1) {
  3.     return window[movieName];
  4.   }
  5.   else {
  6.     return document[movieName];
  7.   }
  8. }
  9. getSWF('myMovie').swfSetTheme(myVar);


That works in Internet Explorer & Opera.

I'm using "AC_FL_RunContent" to display the SWF, here's what that looks like.
Note the use of "'allowScriptAccess" & "'swLiveConnect".
Code: [ Select ]
AC_FL_RunContent('id','myMovie', 'name','myMovie', 'src','/portal/e107_themes/Tech9/tech9', 'movie','/portal/e107_themes/Tech9/tech9', 'width','600', 'height','180', 'allowScriptAccess','sameDomain', 'swLiveConnect','true', 'quality','high', 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','pluginspage','http://www.macromedia.com/go/getflashplayer');


The "call" method of "ExternalInterface" works without a problem in Firefox, I can get Flash to call a JS method & recieve a return value without a problem.

I haven't been able to get JS to talk to Flash though, even if it doesn't want a return value.

This all has to do with syncing the colorschemes between the SWF & HTML/CSS.
When the movie starts, it uses "ExternalInterface.call" to read the same cookie & set itself up as JS reads to set itself up.
JS is used to change the colorschemes at runtime, so I need to be able to have JS talk to Flash as well.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Turns out the issue wasn't Flash at all.

The method being used to get the SWF with JS was returning an nodeList with both the OBJECT & EMBED in Firefox, instead of a single scriptable object as it does in the other browsers.

Here's what I'm using to get reference to the SWF in JS now.
The first element in the nodeList is the OBJECT, the second is the EMBED, which is what Firefox is looking for.
Code: [ Select ]
function getSWF(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  }
  else {
        if(document[movieName].length != undefined){
             return document[movieName][1];
        }
    return document[movieName];
  }
}
  1. function getSWF(movieName) {
  2.   if (navigator.appName.indexOf("Microsoft") != -1) {
  3.     return window[movieName];
  4.   }
  5.   else {
  6.         if(document[movieName].length != undefined){
  7.              return document[movieName][1];
  8.         }
  9.     return document[movieName];
  10.   }
  11. }
  • atrejoe
  • Born
  • Born
  • atrejoe
  • Posts: 2

Post 3+ Months Ago

Bit of a late reply, but I have an additional question.

I had the same issue while accessing javascript-activated flash through javascript in Firefox.

Your explanation clarified my mucking-about in javascript, so now I'm sure I can access the flash-movie itself in firefox, but still I could not call the actionscript method in flash.

I have made the method publicly available by using:
Code: [ Select ]
flash.external.ExternalInterface.addCallback("methodName", instance, method);


This works in most browsers (MSIE, Opera and Safari) except for Firefox. When I disable flash-activation by just displaying the flash movie normally, it works in all browsers. Both methods indicate that the parameter refers to the the same type of object:

Code: [ Select ]
HTMLEmbedElement


Did you experience the same? The method in actionscript is a simple 'void' method, taking three strings as arguments.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Only issue I had with Firefox was the one requiring me to check for an array returned with the JS, if you're getting HTMLEmbed elements returned I don't have any idea what it could be right now. :scratchhead:

I'd say swLiveConnect or allowScriptAccess, but the movies I used before in this thread aren't using thoose paramaters & they work fine in each browser.
  • atrejoe
  • Born
  • Born
  • atrejoe
  • Posts: 2

Post 3+ Months Ago

Thanks for your reply.

Right now it only seems to go wrong when calling the function from Body.onload.

At this time the flash file has not been fully initialized. This seems to be a two-way issue. First of all the loading of the source of the embed tag does not delay the body.onload event (only in Firefox), although it should.
Second of all, I'm performing cross-frame scripting, therefore it would seem extra difficult to tune the timing.

I guess I'll just have to be extra careful while calling the actionscript methods.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 31 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.