views:

1500

answers:

5

Is it possible to start playing a file inside a flash player by making use of javascript code? If so, how would I do it?

+2  A: 

Try using swfObject, you can make any actionscript function visible for javascript using ExternalInterface and declaring them into javascript. So you can trigger actionscript function with play() (or any other code you want) from your javascript code.

Here is an example:

Actionscript:

import flash.external.ExternalInterface;

ExternalInterface.addCallback( "methodName", this, method );
function method() {
   trace("called from javascript");
}

Javascript:

function callAS() {
   swf.methodName(); 
}

Where methodName is the identifier js uses to call the method from actionscript.

totocaster
+1  A: 

Yes it is. You can reference the flash movie objects from js and control the flash component in a page. Unfortunately the way you do it is not portable across browsers. See this:

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

Vasil
See also: http://www.adobe.com/support/flash/publishexport/scriptingwithflash/
jeffamaphone
+1  A: 

Take a look at SWFObject. There a lot of examples on how to accomplish that.

mpeterson
+1  A: 

You can call any custom function in Flash from JavaScript, which requires you coding both Javascript and Flash.

See here for some examples: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683.

Also, using SwfObject helps a long way when dealing with Flash from JavaScript.

Seb
does this mean that I'm not able to play it if the flash part wasn't written by me? I can just add JS code to the page, but not flash.
Geo
No, you can't control compiled flash movie from javascript without using ExternalInterface.
totocaster
@Geo: exactly. If you want to play Flash movies, you need to have complete control over its code and behavior. If it's a third-party movie, then you cannot control it (unless, of course, you decompile it and add some code to it, but that's something you never heard from me :P).
Seb
My plans of world domination are ruined!
Geo
A: 

if any oneneed for nesseray for learning flash i will gave him more informaion about it..

Hosam abuzarqa [email protected]

hosam abuzarqa