Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  96] [ 2]  / answers: 1 / hits: 22225  / 15 Years ago, thu, september 17, 2009, 12:00:00

My simple ActionScript
I am trying to use Flash's ExternalInterface to setup a callback so that JavaScript can call a method on my Flash object. Everything works fine in Safari, Firefox and in IE, but I cannot get Chrome working. When I try the code on Chrome, I get the following error:




Uncaught TypeError: Object #<an
HTMLObjectElement> has no method
'setText'




Here is the example HTML I am using (again, works fine in Safari, FF and IE)



<html><body>
<div id=mycontent></div>
<script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js></script>
<script type=text/javascript>
swfobject.embedSWF(http://invincible.dynalias.com:8080/HelloWorld.swf, mycontent, 400, 420, 9.0.0,expressInstall.swf, {}, {allowScriptAccess:'always'},{id:'hw',name:'hw'});

function getFlash(movieName) {
return ( navigator.appName.indexOf(Microsoft) != -1) ? window[movieName] : document.getElementById(movieName);
}
</script><p>
<input type=text id=exampleText /> <input type=button value=Set Text onclick=getFlash('hw').setText(document.getElementById('exampleText')
.value) />
</body>
</html>


and here is the ActionScript...



package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.external.ExternalInterface;
import flash.system.Security;

public class HelloWorld extends Sprite {

private var textField:TextField = new TextField();
public function HelloWorld() {
Security.allowDomain(*);
ExternalInterface.addCallback(setText, this.setText);
textField.text = Hello, world!;
addChild(textField);
}
public function setText(text:String):void {
this.textField.text = text;
}
}
}

More From » flash

 Answers
118

I got the same problem, to fire and recieve listener events between javascript and flash.



The solution was to use AC_OETags.js file from Adobe as embedd script instead of JQuery flash. (It is found in the zip file under Client Side detection, Adobe probably have it some other places as well)



The trouble based on a race condition when the flash builds the javascript callbacks in the browser. This is not handeled correctly by a straight embed for some reason.



<div>
<script>
// Major version of Flash required
var requiredMajorVersion = 10;
// Minor version of Flash required
var requiredMinorVersion = 0;

var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
AC_FL_RunContent(
src, tagflash,
width, 200,
height, 200,
id, myTagFlash,
quality, high,
bgcolor, #FFFFFF,
name, myTagFlash,
allowScriptAccess,always,
type, application/x-shockwave-flash,
pluginspage, http://www.adobe.com/go/getflashplayer,
flashvars, templateData=theYear:2010&theTagNumber:123
);
</script>
</div>


Then you can do: (works in IE, FF, Safari, Crome,++)



$(#tagFlash).gotoNewFrame();

[#98678] Sunday, September 13, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wilson

Total Points: 27
Total Questions: 93
Total Answers: 93

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
wilson questions
Tue, Aug 9, 22, 00:00, 2 Years ago
Wed, May 11, 22, 00:00, 2 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;