A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Pull variable FROM AS3 to javascript function?

Hybrid View

  1. #1
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    It's not clear whether you're calling AS from JS or vice versa. If AS is calling JS, then you can simply pass parameters in the ExternalInterface calls.

    Code:
    ExternalInterface.call("someJSFunction", currentTrack, isPlaying);
    If you are calling AS from JS, you could create and expose getter functions for your properties
    Code:
    private function getCurrentTrack():String{
      return currentTrack;
    }
    private function getIsPlaying():Boolean{
      return isPlaying;
    }
    //...
    ExternalInterface.addCallback("getCurrentTrack", getCurrentTrack);
    ExternalInterface.addCallback("getIsPlaying", getIsPlaying);
    Javascript can then call those methods to get your values.

  2. #2
    Member
    Join Date
    Feb 2008
    Posts
    31
    Thanks for the reply.

    sorry to be confusing. I am grabbing the variables, that are constantly changing, out of the swf(mp3 player) and using them in a javascript function.


    Just so that i understand:

    AS3:
    Code:
    private function getCurrentTrack():String{
      return currentTrack;
    }
    private function getIsPlaying():Boolean{
      return isPlaying;
    }
    Javascript or AS3?:
    Code:
    ExternalInterface.addCallback("getCurrentTrack", getCurrentTrack);
    ExternalInterface.addCallback("getIsPlaying", getIsPlaying);
    Currently i am using this:
    AS3:
    Code:
    public function initFunction() {
       updateStatusToPage();
    }
    private function getCurrentTrack():String{
      return currentTrack;
    }
    private function getIsPlaying():Boolean{
      return isPlaying;
    }
    private function updateStatusToPage() {
    			ExternalInterface.addCallback("getCurrentTrack", getCurrentTrack);
    			ExternalInterface.addCallback("getIsPlaying", getIsPlaying);
    			var result:Boolean = ExternalInterface.call("jsFunction_Update");
    			trace (ExternalInterface.available); // Trace = TRUE
    }
    javascript:
    Code:
    <script language="javascript">
    	function jsFunction_Update() {
    		javascript:updateStatus(currentTrack, isPlaying);
    		return false;
    	}
    </script>
    then the idea is that dynamically form the outside script i can pass:
    Code:
    javascript:updateStatus(4, true);
    when i go to another page so that it will continue where i left off on my playlist

    see any reason this isnt working. I'm just not familiar with talking outside of my swf.

    thanks again

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