-
JS to SWF
Hi,
I have been having some problems passing information from JS to a SWF
What i want to so is when i press a BTN in my HTML Page that it calles a JS Funcrion and calls a function inside flash.
any ideas how to do this?
my SWF is really simple i just have 1 text field called myText and on the action leyer i have
code:
pickTest = function(){
myText.text = "123"
}
HTML HEADER
HTML Code:
<script language="javascript" type="text/javascript">
function getText(returnText){
alert(returnText)
if (navigator.appName.indexOf("Microsoft") != -1){
window["spell_check"].pickTest();
}else {
document["spell_check"].pickTest();
}
}
</script>
BODY
HTML Code:
<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '550',
'height', '400',
'src', 'spell_check',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'spell_check',
'bgcolor', '#ffffff',
'name', 'spell_check',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'spell_check',
'salign', ''
); //end AC code
}
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="spell_check" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="spell_check.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> <embed src="spell_check.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="spell_check" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</noscript>
<input type="button" value="OpenNewWindow" onclick="getText(123)" />
Thanks for all the help
-
You need to use ExternalInterface, and specifically the addCallback method to register pickTest as a function callable from javascript. You should also change the way you're defining pickTest.
Code:
function pickTest():void{
myText.text = "123"
}
ExternalInterface.addCallback("pickTest", pickTest);
Edit: It probably doesn't fit your needs exactly since it was written for class based rather than frame based code, but I wrote up a utility to help out with some ExternalInterface stuff. http://cosmodro.me/blog/2008/aug/31/expose-your-tool/
As always with ExternalInterface, it must be on an actual webserver to work. Testing on the local filesystem doesn't work.
-
so if i am in localhost this will not work?
-
localhost should work, so long as you're serving it from an actual webserver. Does your url start with http:// or file://? The former will work, the latter won't.
-
i moved the code to a testing server
http://www.wilopenwindows.com/_test/...S/Default.aspx
but i am still getting a error
window.spell_check is null or not a object
-
Your object/embed needs to have an id. And your crossbrowser stuff doesn't work for firefox. It should be something like
Code:
document.getElementById("spell_check").pickTest();
Look into swfobject, which makes embedding flash a lot easier than the AC_FL_RunContent crap that adobe publishes.
-
i just updated my code to use
document.getElementById("spell_check").pickTest();
but i am getting a new error that reads
Object does not support this property ot method
and BTW thanks you so much 4 helping me out
-
It's a two part fix. First you have to fix the embedding code so that it does put an id on the thing. Then you need to access it correctly.
Which browser are you using?
-
FWIW, i'm using moofx's swiff class to link flash and js tweens. i can run it from file:/// just fine
-
Interesting. I'm assuming that still uses ExternalInterface for the js->flash communication. I wonder if Adobe fixed that thorn in my side with the 10 player. There was no good reason for it to fail on file:// pages in the first place.
Can you provide some links to moofx swiff? I'm having a bit of trouble finding good documentation online.
-
this is my new flash code
import flash.external.*;
function pickTest() {
myText.text = "123";
}
ExternalInterface.addCallback("pickTest", this, pickTest);
-
ExternalInterface.addCallback only takes 2 arguments. It shouldn't even compile the way you have it there. Remove the "this" argument.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|