PDA

View Full Version : Javascript -> Flash


Grofit
11-21-2006, 11:41 AM
Ive been looking on the net for the past few days looking at the best way to get a simple variable to flash... ideally it would be great to have a way to run actionscript functions from javascript. I have looked into the javascript integration kit, but i didnt really like having to include files everywhere just to do something which i think is simple.

Before you all start shouting FLASH VARS at me, i need it to be dynamic, so i can have a textbox on a page and when they click a button it grabs that data from the textbox and spams it over to flash. This needs to be done via javascript without refreshing the page. This makes things a tad more complicated as you cant just do OnClick="location.href=index.php?var=blah;" then set var to the flashvar embed, as this will refresh the page.

I hope im explaining this ok so far :).

So im basically wondering if there is a simple way to send a variable to a static embedded flash file via javascript. Im able to currently do document.flashobj.gotoFrame(x) quite happily and i thought that i could do document.flashobj.SetVariable("name", value), however that doesnt seem to work...

Im trying to make it cross platform as well... any help would be great.

algorithm0
11-21-2006, 02:44 PM
Evidently Flex has facilities for this... but I'm not quite ready to move into that yet. Flash 8 also has some new thing called ExternalInterface that supposedly will let you talk between js and actionscript.

If you're well versed in flash then you might want to try the two above concepts. If you're like me and you want to stick with something less advanced, then try the flash javascript integration kit. I hadn't much luck with the official releases, but I found a modified version that works well for me.

Official site: http://osflash.org/doku.php?id=flashjs

Modified Version: http://blog.deconcept.com/code/intkit/
(download the zip file)

I hope this helps!

jsebrech
11-21-2006, 03:06 PM
If you can restrict yourself to flash 8 and above, you can use ExternalInterface. This way no javascript includes are necessary.

Grofit
11-22-2006, 10:11 AM
Flash 8 suits me fine, to be honest i dont like bloating any of my web things with anything that doesnt NEED to be there, most people are using flash 9 now anyway as far as i can tell so yeah im fine with that. Thanks for the advice guys!

algorithm0
11-22-2006, 08:54 PM
I tried using ExternalInterface for the first time today and found it is soooo simple to use. I would recommend it over the flash js integraiton kit any day! I wish I had known about ExternalInterface before I spent days getting the integration kit to not work.