confused.com
08-12-2009, 04:04 PM
Hi,
I'm struggling to output a value in Actionscript into Javascript (hope this is the right place to ask).
Basically, I have the following code to find the bandwidth of a player:
public function onBWCheck(... rest):Number {
return 0;
}
var p_bw:Number;
public function onBWDone(... rest):Number {
if (rest.length > 0)
{
p_bw = rest[0];
trace(p_bw);
return p_bw;
} else {
trace(p_bw);
return 0;
}
}
But in AS it outputs a value of 0 first, then the correct bandwidth (eg 14444). In my javascript page I want to output this correct bandwidth as an alert. I am trying to use a callback function - but I'm a real novice!
My javascript is:
function showBandwidth(){
var player = document.FLVClipEditor;
if (player)
{
var bandwidth = player.getCurrentBandWidth();
if(bandwidth > 0){
alert(bandwidth);
} else {
if(player.setBandwidthCallback)
{
player.setBandwidthCallback("showBandwidth");
alert("no good");
}
}
} else {
alert("Sorry, the flash player is not available");
}
}
And my AS for the function is:
public function setBandwidthCallback(callbackName:String):void
{
if (player)
{
var callbackFunction:Function = function() {
ExternalInterface.call(callbackName, ExternalInterface.objectID);
};
player.addEventListener("getCurrentBandWidth", callbackFunction);
}
}
I just don't fully understand what I'm doing here and can't find any help docs to help. Any tips would be lovely :)
I'm struggling to output a value in Actionscript into Javascript (hope this is the right place to ask).
Basically, I have the following code to find the bandwidth of a player:
public function onBWCheck(... rest):Number {
return 0;
}
var p_bw:Number;
public function onBWDone(... rest):Number {
if (rest.length > 0)
{
p_bw = rest[0];
trace(p_bw);
return p_bw;
} else {
trace(p_bw);
return 0;
}
}
But in AS it outputs a value of 0 first, then the correct bandwidth (eg 14444). In my javascript page I want to output this correct bandwidth as an alert. I am trying to use a callback function - but I'm a real novice!
My javascript is:
function showBandwidth(){
var player = document.FLVClipEditor;
if (player)
{
var bandwidth = player.getCurrentBandWidth();
if(bandwidth > 0){
alert(bandwidth);
} else {
if(player.setBandwidthCallback)
{
player.setBandwidthCallback("showBandwidth");
alert("no good");
}
}
} else {
alert("Sorry, the flash player is not available");
}
}
And my AS for the function is:
public function setBandwidthCallback(callbackName:String):void
{
if (player)
{
var callbackFunction:Function = function() {
ExternalInterface.call(callbackName, ExternalInterface.objectID);
};
player.addEventListener("getCurrentBandWidth", callbackFunction);
}
}
I just don't fully understand what I'm doing here and can't find any help docs to help. Any tips would be lovely :)