Log in

View Full Version : Javascript -> Flash: Can't find a tutorial.



jlizarraga
05-08-2008, 11:48 PM
Hello!

I'm trying to make a Flash movie play after the page has fully loaded using <body onload="">.

The only tutorial I could find (I must be using some terrible search terms) on Google to communicate to a Flash video using javascript was the following:

http://www.permadi.com/tutorial/flashjscommand/

Which is probably very outdated. I found a 2004 forum post trying to use the same method, which the author there said "used to work but doesn't anymore." But it works on the initial tutorial page...

It seems like maybe older versions of Flash supported this method, but the newer ones don't?

Check out the page in question:

http://futureford.autofusion.com/test.html

How do you use javascript to command a Flash movie these days? I have the <object> set with an id of "homepageflash" and the <embed> set with a name of "homepageflash", but using the methods in the tutorial no matter how I try to reference homepageflash I get a javascript error telling me the object has no properties in both IE and FF.

Any help or a link to a more modern approach would be greatly appreciated.

Medyman
05-08-2008, 11:59 PM
http://weblogs.macromedia.com/flashjavascript/
http://www.moock.org/webdesign/flash/fscommand/index.html

jlizarraga
05-09-2008, 12:04 AM
Thanks for the post, but according to the vague hints I find via google, those are both deprecated ways of doing this.

I found this:

http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002200.html

But I need functional examples/tutorials to understand it.

Medyman
05-09-2008, 12:28 AM
Hmm...so it seems they are. I was trying to avoid recommending the External API. It's a doozy if you're just starting out with ActionScript (which I realize you might not be).

Why do you want to do this by the way? Is it just a matter of timing the start of the flash movie?

Anyway, this (http://www.adobe.com/devnet/flash/articles/external_interface.html) should get you started.

jlizarraga
05-09-2008, 05:12 PM
THANK YOU SO MUCH FOR THE LINK!

I should be alright, I've been using Flash since Flash 5 (just a little here and there over the years, though).

You can see why I want the page to load before the flash movie here:

http://futureford.autofusion.com/

Thanks again for the link, this seems like exactly what I was looking for. If you don't mind my asking, how did you find it?

Medyman
05-09-2008, 05:53 PM
If you don't mind my asking, how did you find it?

I googled "External API". That's the common name for the externalInterface class.

I was actually trying to look for something else that I used to learn how to use the External API when I first used it, but I couldn't find that. What I linked looked fairly good though.

jlizarraga
05-09-2008, 06:09 PM
Okay now this is very strange, at least to a supernewb like myself. The link you gave and the examples it contained were wonderful and easy to understand. However I may have found a limitation in the Flash External API? I dunno, check it out:

http://futureford.autofusion.com/ExternalInterface_addCallback.html

That is the example from the link you provided on communicating from Javascript to Flash. Check out the source on that page. Why is that this works:

onClick="callExternalInterface()"

But this doesn't:

onLoad="callExternalInterface()"

:confused::confused::confused:

Right on the same page! How is it that the "not a function" javascript error comes up with one way of calling the function but not the other? Is there a workaround? I really need that function to fire onLoad.

Thanks a bunch for any help.

jlizarraga
05-09-2008, 06:19 PM
I should mention that the onLoad only fails in Firefox. In IE it works as expected, but I'm guessing FF is the one performing correctly as usual?

Medyman
05-09-2008, 06:19 PM
Umm...no, you can use onLoad with the External API. I'm not a JavaScript expert so I can't be sure but there are different ways to call the Flash object depending on browsers. That might be causing a problem. Because it seems like it works in IE and Opera. Seems like Fx is the one with the problem.

You might want to give this (http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001064.html) a read and the links/leads on that page.

jlizarraga
05-09-2008, 06:23 PM
But I'm just calling the same function two different ways. Why wouldn't the onLoad work for the External API example functions when onClick works just fine? That makes no sense to me.

jlizarraga
05-09-2008, 06:55 PM
Umm...no, you can use onLoad with the External API. I'm not a JavaScript expert so I can't be sure but there are different ways to call the Flash object depending on browsers. That might be causing a problem. Because it seems like it works in IE and Opera. Seems like Fx is the one with the problem.

You might want to give this (http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001064.html) a read and the links/leads on that page.

Thanks for this link, too, but the example there produces the same error in Firefox.

They have the initialize() function being called onLoad in the <body> tag, but all it's doing is browser sniffing. If you add in any lines that (try to) affect the Flash movie directly to that function, you get the "not a function" error in Firefox, but again only when using the function via onLoad.

There is definitely something going on here. There has to be a workaround.

:(

jlizarraga
05-09-2008, 07:02 PM
Okay I found some better search terms for Google (this very thread even came up - I had no idea Google indexed things so fast). Other people have had this problem:

http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001600.html

Check the comments.


QuantumDynamix said on Oct 24, 2006 at 11:01 AM :

No matter how I approach this, I consistantly get an error in Firefox:

thisMovie("movieID").functionName is not a function.

This works PERFECTLY in IE, but keeps giving me problems in Firefox. Any help?

persisjas said on Mar 28, 2007 at 7:26 PM :

When i attempted to write into the text input from the JS, it worked. However, my flash cannot write out from the swf into the javascript.

Is there something wrong with my system? I'm using Flash 8 Professional, running on XP SP2

No screen name said on Jun 13, 2007 at 7:23 PM :

I'm having the same issue as QuantumDynamix. Anyone know what's going on?

No screen name said on Jun 19, 2007 at 2:43 PM :

QuantumDynamix: I think I know what your problem is

You are calling your thisMovie("movieID").functionName during your webpage's onload event? If so the problem is that the Flash isn't fully loaded in FF on the page onload event. I suggest that you make a function in your Flash that calls a javascript function that calls your thisMovie("movieID").functionName function(s). That should fix your problem and should involve very little code change.

I will let you guys know if this is a solution for me.

jlizarraga
05-09-2008, 07:11 PM
YAY I SOLVED IT GO NEWB POWER GO

So after reading in the quoted text above that the Flash is not fully loaded when the body's onload event fires, I just put a 1 MILLISECOND (yes I'm serious) delay before the function is fired and it fixed the problem.

What a craptacular headache!

jlizarraga
05-09-2008, 07:13 PM
Whoops, turns out 1 millisecond is enough for that tiny test page, but for the actual website this is all relating to I had to use 50.

HUGE thanks goes out to Medyman who I would still be at square 1 without.

Medyman
05-09-2008, 08:01 PM
Glad you got it working :D.

jlizarraga
05-09-2008, 10:05 PM
Something to be wary of for Dreamweaver users who find this thread:

You know the runactivecontent script that dreamweaver gives you so that IE users don't have to click your flash to use it? That script seems to break the External API. And for some reason using the External API with your flash movie disables the need to first activate a flash movie in IE just the way the runativecontent script does.

:shrug: