Returning value from a javascript to actionscript call problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfsiddiq
    New Member
    • Aug 2007
    • 17

    Returning value from a javascript to actionscript call problem

    HI

    I am facing some problem with my as-js communication.I am passing a String expression to a javascript function using ExternalInterfa ce.call function upon mouse click.My string expression is as follows
    str="x=callAS(i d)"
    Inside my js function i am just using eval(str).callA S(id) contains a call to actionscript function to retrive the value of x using id.I am able to make call to the actionscript by registering the function using ExternalInterfa ce.addCallBack( "callActionScri pt",A SFunction) but the transfer doesnt return to the js on return i.e the value of x is not getting populated with the retrieved value.My function in actionscript is like this
    public function ASFunction(id:S tring):Number
    {
    return 6;

    }
    This 6 have to be returned to js thereby populating x=6;which is not happening.Any suggestions will be of great help

    Cheers
    Mfsiddiq
  • rsdev
    New Member
    • Jul 2007
    • 149

    #2
    Originally posted by mfsiddiq
    HI

    I am facing some problem with my as-js communication.I am passing a String expression to a javascript function using ExternalInterfa ce.call function upon mouse click.My string expression is as follows
    str="x=callAS(i d)"
    Inside my js function i am just using eval(str).callA S(id) contains a call to actionscript function to retrive the value of x using id.I am able to make call to the actionscript by registering the function using ExternalInterfa ce.addCallBack( "callActionScri pt",A SFunction) but the transfer doesnt return to the js on return i.e the value of x is not getting populated with the retrieved value.My function in actionscript is like this
    public function ASFunction(id:S tring):Number
    {
    return 6;

    }
    This 6 have to be returned to js thereby populating x=6;which is not happening.Any suggestions will be of great help

    Cheers
    Mfsiddiq
    Adobe recommend using this in Javascript;

    Code:
    <form>
        <input type="button" onclick="callExternalInterface(id)" value="Call ExternalInterface" />
    </form>
    <script>
    function callExternalInterface(id) {
        thisMovie("externalInterfaceExample").callAS(id);
    }
    
    function thisMovie(movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[movieName]
        }
        else {
            return document[movieName]
        }
    }
    </script>
    Actionscript;

    Code:
    var wasSuccessful:Boolean = ExternalInterface.addCallback("callAS", id, ASFunction);
    
    var txtField:TextField = this.createTextField("txtField", this.getNextHighestDepth(), 0, 0, 200, 50);
    txtField.border = true;
    txtField.text = wasSuccessful.toString();
    
    public function ASFunction(id:String):Number
    {
    return 6;
    }
    Try this and let me know if I can help further.

    Comment

    • mfsiddiq
      New Member
      • Aug 2007
      • 17

      #3
      Srry for disturbing u guys.It was just a silly mistake.Forgot to give a return statement in the javascript.Anyw ayz alls well that ends well
      Cheers
      mfsiddiq

      Comment

      Working...