Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

javascript-flash communication

Posted on 2004-11-18
7
Medium Priority
?
342 Views
Last Modified: 2008-03-10
Can anyone tell me if there are any other alternatives for javascript to communicate with a flash file other than using the setVariable() method as a flag to call flash methods? Also, does anyone know of how I could cache my processing so that javascript will wait for flash and vice versa?

blu.
 
0
Comment
Question by:blue-genie
7 Comments
 
LVL 9

Expert Comment

by:rexmor
ID: 12621017
how about localConnection.. http://www.macromedia.com/support/flash/ts/documents/localconnection.htm

or SharedObjects...
0
 
LVL 39

Author Comment

by:blue-genie
ID: 12622646
Hi Rex. it's my colleague asking this question.
he's a java programmer, what he's basically wants to know is, can you use javascript to call a method in flash, and if yes, how would you do this.

blu.
0
 
LVL 1

Expert Comment

by:andreas_d
ID: 12628835
here is my way

see this how to properly embed the movie : http://www.moock.org/webdesign/flash/fscommand/#javascripttoflash

i think it is not possible to call a method directly in flash. therefore i use a setter function to transport the parameters and a getter function to fetch the result. (obj.addProperty(n,s,g))
here are my files:
http://home.pages.at/andreas-deschka/xy.fla
http://home.pages.at/andreas-deschka/xy.html

<script language="javascript">
var cf=function(fn){
      var r= new Array();
      for(var i=0; i< arguments.length-1; i++){
            r.push(arguments[i+1]);
      }
      document.xy.SetVariable(fn, r.join(";"));
 // i pass the arguments converted to a string
      return document.xy.GetVariable(fn);
}      
</script>
<a href="javascript:alert(cf('obj.multiply',45,3));">click</a>

Andreas
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:negatyve
ID: 12643914
Yep, there is. Use SetVariable to pass arguments, and TCallLabel to invoke the script (pseudo function call):

http://www.macromedia.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html#70479
0
 
LVL 39

Author Comment

by:blue-genie
ID: 12644005
neg.

Glad you're around, I told my colleague if any one can answer this it would be you.

What he's trying to do is, using Javascript, calls a method in Flash, its not parsing anything to the Flash, the Javascript must then wait for a return value from the flash method, before it proceeds with anything else.

Can this be done, can you help with an example?
Many thanks,
blu.

0
 
LVL 27

Accepted Solution

by:
negatyve earned 2000 total points
ID: 12644539
Hi, blue.. :)

Well, I think that you could use Object.watch to look for changes on a variable in flash, but not the same by javascript side. I think you should go with simple function calls:

- javascript set a variable in flash, then call the function (SetVariable + TCallLabel)
- flash, when done, calls back javascript (getURL("javascript:function(parameters)");)
0
 
LVL 39

Author Comment

by:blue-genie
ID: 12652062
Ok, thanks neg.

We're gonna work on it for a while and I'll get back to you.

It makes sense.

blu.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question