Skip to main content
June 16, 2012
Answered

Actionscript external interface onload

  • June 16, 2012
  • 1 reply
  • 3012 views

Hi

I Have this external interface code that sends a video url to a video player when a user clicks a button it goes some thing like this:

<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
function callJavascript(sendText){

   window.document.myMovie.SetVariable("testValue", sendText);
}

  });
</script>

The code above works fine when a user click a button with onclick the passed variable is a video url

and is send to the player.

The problem is I would like to get the video url passed when the page is loaded.

I have tried.

<script language="JavaScript" type="text/javascript">

$(document).ready(function() {

 

var sendText=$("Videosroll/Videos/1.flv").val();                                                                     

window.document.myMovie.SetVariable("testValue", sendText);

}

</script>

This does not work. I think its because the videoplayer is not fully loaded when this action is called. 

I have looked at javascript timers etc. If any one has a solution please help.

This topic has been closed for replies.
Correct answer kglad

Hi Kglad

Thank you so much for the assistance. Sorry for the javascript changes I made I had turned the function into callnow.

I falled message 7.



function callnow(){

return "Videosroll/Videos/1.flv";

}

Action script:

import flash.Exteneral.ExternalInterface;

var videoURL:String=ExternalInterface.call("callnow");

tf.text=videoURL;

myVid.play(videoURL);

HTML

<body onload="callnow()"></body>

The textfield is dynamic instance name tf. When I run the code textfield goes undefined.


the actionscript is calling the callnow function.   there's no need for that onload="callnow()".

copy and paste the actionscript you're using.  if that is copied and pasted, you have a typo in you import statement that needs to be fixed.

1 reply

kglad
Community Expert
Community Expert
June 16, 2012

use the externalinterface call() method to call callJavascript() (but it wouldn't make any sense to have flash pass sendText so that should be variable in callJavascript() )

June 16, 2012

Hi

Thanks for the reply. I am not sure what you mean. But on the callJavascript()

<input type="button" onclick="callJavascript(videourl)" value="click me"/>

is used and passes the videourl to play. Which works fine.

The second part is an attempt to do the same but when the page is loaded. This is where

the problem lay.

thank you.

kglad
Community Expert
Community Expert
June 16, 2012

again,  in your html use:

<script language="JavaScript" type="text/javascript">

function callJavascript(){

  return videourl;  // <- make sure this is defined.  if it's not defined when your page loads, use a loop in flash to keep calling until it is defined.
}


</script>

// in flash, use:

import flash.Exteneral.ExternalInterface;

var videoURL:String=ExternalInterface.call("callJavascript");

// do whatever with videoURL;