A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: AS3 + Javascript communication

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    5

    AS3 + Javascript communication

    Hello,

    So basically, I have a javascript array and a function on my html page, and I need actionscript to be able to pick the right one from the array and run the function based on what button I pushed.

    My javascript is:
    Code:
    <script>
            navArray = new Array();
    
            navArray["home"] = "../index.aspx";
            navArray["about"] = "../about.aspx";
            navArray["contact"] = "../contact.aspx";
            navArray["services"] = "../services.aspx";
            navArray["mediainterface"] = "../mediainterface/";
            navArray["photogallery"] = "../photogallery/";
    
            function navigate(which) {
    
                if (window.opener) {
    
                    if (which == "contact" || which == "services")
                    {
    	                window.open (navArray[which], 'newWin')
                    }
                    else if (which == "photogallery" || which == "mediainterface")
                    {
    	                window.location = (navArray[which]);
                    }
                    else 
                    {
    	                window.opener.location = navArray[which];
    	                opener.window.focus();
                    }
            	
                }
                else 
                {
                    window.location = (navArray[which]);
                }	
    
            }
    </script>
    I'm a little lost on the AS part of it, what would be the best way to have the each different button run it's respective part in the JS array/function?

    Thanks

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    PHP Code:
    ExternalInterface.call('navArray''photogallery'); 

  3. #3
    Junior Member
    Join Date
    Feb 2009
    Posts
    5
    Hmm, it's not doing anything,

    I imported the external interface class
    Code:
    import flash.external.ExternalInterface;
    and other things work with it. Am I missing something?

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Whoops - that should be targetting "navigate" not "navArray" - first param is the function, after that it's arguments you want to pass.

  5. #5
    Junior Member
    Join Date
    Feb 2009
    Posts
    5
    Awesome that worked. Thanks!

  6. #6
    I Love India Nalini_v's Avatar
    Join Date
    Jun 2007
    Location
    Chennai
    Posts
    195
    hi. I want the source sample of ur code.. i too tried the same but it seems not working for me...

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center