Results 1 to 7 of 7

Thread: ExternalInterface/Javascript

  1. #1
    114
    posts
    Registered User

    ExternalInterface/Javascript

    I have a little problem that I've spent hours trying to figure out. I am trying to return an array from javascript. The problem (I assume) is that is has some php in the javascript function

    Here is the code I am trying that doesnt work:
    JavaScript:
    <script type="text/javascript">
    function JavaFunc(){
    <?php
    $company_name[0] = "Kirupa";
    echo 'var company_name = new Array();';
    echo 'company_name[0] = '.$company_name[0].';';
    echo 'return company_name;';
    ?>

    }
    </script>


    AS3
    var theArray = ExternalInterface.call("JavaFunc");
    theTextField.text = theArray[0]


    if I change the javascript code to....

    <script type="text/javascript">
    function JavaFunc(){
    <?php
    echo 'var company_name = new Array();';
    echo 'company_name[0] = "Kirupa";';
    echo 'return company_name;';
    ?>

    }
    </script>
    The textfield text is the first element of the array as it should. There must be something wrong with the way I'm echoing out the java from php. If anyone can help me understand what I'm doing wrong I would greatly appreciate it.

  2. #2
    your echo is returning the String 'return company_name;'

    it should be returing 'return'.$company_name;

    because you want the value of $company_name; not a string that says $company_name,

    ya dig?

  3. #3
    114
    posts
    Registered User
    Quote Originally Posted by GrndMasterFlash View Post
    your echo is returning the String 'return company_name;'

    it should be returing 'return'.$company_name;

    because you want the value of $company_name; not a string that says $company_name,

    ya dig?
    What's up GrndMasterFlash. It's been a while since I've had the honor. Thanks for your reply and sorry for the delay. OK so I tried your suggestion however it's not working for me. The problem is when I echo the php variable (echo 'return' .$company_name, $company_name comes through as string "Array". The only was that I know how to communicate between php and javascript is to echo my javascript as string in the correct syntax.

  4. #4
    20
    posts
    Registered User
    I think that your php code an javascript code is correct.
    Could you try following code in flash and see that work well or not.
    ExternalInterface.call("alert","A try!");

  5. #5
    114
    posts
    Registered User
    Quote Originally Posted by Ning View Post
    I think that your php code an javascript code is correct.
    Could you try following code in flash and see that work well or not.
    ExternalInterface.call("alert","A try!");
    Thanks for the reply Ning. That worked fine.

  6. #6
    20
    posts
    Registered User
    I am sorry, I did not see clearly...

    echo 'company_name[0] = '.$company_name[0].';';
    echo 'company_name[0] = "'.$company_name[0].'";';

    Do you understand what I mean?

  7. #7
    114
    posts
    Registered User
    Quote Originally Posted by Ning View Post
    I am sorry, I did not see clearly...

    echo 'company_name[0] = '.$company_name[0].';';
    echo 'company_name[0] = "'.$company_name[0].'";';

    Do you understand what I mean?
    It's alive! I deleted all other java functions and like magic the original approach works. I think that other functions may have conflicted with this one but still not sure why. Thanks for looking at this for me guys. I appreciate your help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012