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.
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.
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;
Hi
This is extremely helpful. My current actionscript is:
var testValue:String = "";
watchCallback = function (id, oldval, newval):String {
result_txt.text = newval;
myVid.play(newval);
return newval;
};
_root.watch("testValue", watchCallback);
HTML/PHP:
<?Php
//This is a while loop with many videourls and thumb images. When clicked the javascript passes the video url to flash.
<a href="" onclick="return false" class="gt" name="'.$vidfield.'"><img src="'.$vidthumb.'" width="180" height="105" align=center /></a>
?>
Current javascript:
<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
$(".gt").live("click", function(){
var sendText = $(this).attr("name");
window.document.myMovie.SetVariable("testValue", sendText);
});
});
</script>
The attempt is to automaticly send the a video url onload. So using your advice I added this to current code:
HTML:
<body onload="callnow(videourl)"></body>
Javascript:
<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
function callnow(videourl){
return videourl;
}
});
</script>
Actionscript 2.0:
import flash.Exteneral.ExternalInterface;
var videoURL:String=ExternalInterface.call("callnow");
//Videoplay called myVid.
myVid.play(videoURL);
This has failed to play the video url onload. Other effort include changing callnow function to:
function callnow(videourl){
window.document.myMovie.SetVariable("videoURL", videourl);
return videourl;
}
This has not been a success. I hope you can help and thank you again.
Hi
Just gave it a try. mite be a syntax error.
HTML:
<body onload="callnow()"></body>
JAVASCRIPT:
<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
function callnow(){
return "Videosroll/Videos/1.flv";
}
});
</script>
ACTIONSCRIPT:
import flash.Exteneral.ExternalInterface;
var videoURL:String=ExternalInterface.call("callnow");
//Videoplay called myVid.
myVid.play(videoURL);
I must say I am using actionscript 2.0. also. On callnow in actionscript should they be a () at the end. Like callnow() etc.
Thank you.
i have no idea why you keep changing the javascript code i suggest. the only javascript needed is in message 7. that's it.
if that fails, add a textfield, assign it an instance name (eg, tf) and use the following actionscript:
import flash.Exteneral.ExternalInterface;
var videoURL:String=ExternalInterface.call("callnow");
tf.text=videoURL;
myVid.play(videoURL);
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.
North America
Europe, Middle East and Africa
Asia Pacific