Hi Tracy,
 
There is no callFunction(..) like method for flash activeX or plugin. But
there is setVariable(..) method. 
 
Yes, you can set a variable or setter from Javascript using setVariable
function. I have create a example, it allows you to execute flex function
from javascript...

It's very basic example but you can adopt similar approach and do it more OO
way by creating classes in JS and AS...

 
1) FlexJSExample.jsp
 
<%@ taglib uri="FlexTagLib" prefix="mm" %>
<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html;  charset=ISO-8859-1">
<TITLE>Flex-JS Communication Demo</TITLE>
 

<script language="javascript">
   
 
//this function return to Flash ActiveX Object or Plugin depending upon
browser
//it takes care for browser type and returns the proper reference.
//Accepts the id or name of <OBJECT> or <EMBED> tag respectively
function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName];
 
  } else {
   return window.document[movieName];
  }
}
 

/**###############################################**/
//success flag, set by flash/flex app
var bFunctionCallFinished = true;
//param delimiter, kind of unique string
var paramDelimiter =  "-->$$###$$##$$<--";
 
//this function would call a flash/flex function.
function callFlashFunction(functionName, paramsArray)
{
    if(bFunctionCallFinished) 
    {
        //Get the reference so activeX or Plugin.
     var flashObject  = thisMovie("flexApp");
     
        bFunctionCallFinished = false;
        flashObject.SetVariable("functionName", functionName);
        flashObject.SetVariable("functionParams",
paramsArray.join(paramDelimiter));
        flashObject.SetVariable("commitFunctionCall", true);
    }
    else
    {
        //if previous function call is still being run, you can use
setTimeOut etc to call it little later...
    }
    
}
 
/**###############################################**/
 
</script>
</HEAD>
<BODY bgcolor="#FFFFFF">
 
<!-- look at "flexApp" id/name, thats being used(in JS) to get the reference
of Flash Player in browser. -->
 
<mm:mxml border="1" id="flexApp" name="flexApp">
 
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"; width="600"
height="600" backgroundColor="#FFFFFF" >
 <mx:Script>                    
 <![CDATA[
 
 
     /**################################################**/
     
     //the name of the function to be called.
  var functionName:String;
  //the params delimited by paramDelimiter
  var functionParams:String;
  //param delemiter, kind of unique string 
  var paramDelimiter =  "-->$$###$$##$$<--";
  
  //setter, which executes the function and send the success flag back to
javascript
  public function set commitFunctionCall(flag:Boolean):Void
  {
      var func:Function = this[functionName];
      
      func.apply(this, functionParams.split(paramDelimiter));
      getURL("javascript:bFunctionCallFinished=true;void(0)");
  
     }
     
     /**################################################**/
         
     
     function sayHi(name:String)
     {
         alert("Hi " + name);
         _ta.text += name + newline;
     }
 
     
     function setNum()
     {
         var n = arguments.length;
         for(var i=0;i<n;i++) 
         {
             _ta.text += arguments[i] + newline;
         }
     }             
                                 
  
  
 ]]>
 
 
 </mx:Script>
 <mx:TextArea id="_ta" width="200" height="200"/>                
      
</mx:Application>
</mm:mxml>
 
<input type="button" value="Say Hi" onclick="callFlashFunction('sayHi',
['Abdul']);"/>
<input type="button" value="Send Number"
onclick="callFlashFunction('setNum', [1,2,3]);"/>
</BODY>
 
</HTML>
 
 
 
 
BTW! Based on above principle, I made a JS-Flash libarary long back. Take a
look at it for an idea...

http://www.abdulqabiz.com/files/JSFC/JSFCommunicator%20Library.htm


Hope that helps

-abdul
 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 28, 2005 9:56 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Is there a javascript flashObj.callFunction(), like
setVariable?



Using javasript in a custom HTML wrapper, Is there flashObj.callFunction(),
like there is a setVariable() method?

Or will setVariable() work with a setter method? (Hmm, surely I can create a
setter in mxml, right?)

Tracy


________________________________

Yahoo! Groups Links


*       To visit your group on the web, go to:
        http://groups.yahoo.com/group/flexcoders/
          
*       To unsubscribe from this group, send an email to:
        [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> 
          
*       Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> . 






 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Attachment: Flex_JSCommunication2.jsp
Description: Binary data

Reply via email to