Passing Variables From Javascript to AS3
Hey, new here and in a major bind. I need to pass a variable back to flash from my Javascript. The variable will change which video is being playing in the .swf by click on the link.
HTML:
<a href="javascript:void(0);" onClick="swapVideo();" ><i>Video</i></a>
JAVASCRIPT CODE:
var flashVidSource;
flashVidSource = 'video1';
//swapVideo when bio is clicked
function swapVideo(str)
{
//point to flashVideo player
getFlashMovie("introPlayer.swf").sendToActionscrip t(str);
//check conditional value
if(flashVidSource == 'video1')
{
//toggle from video1 to video2
flashVidSource = 'video2';
}else{
//toggle from video2 to video1
flashVidSource = 'video1';
}
//pass the string to introPlayer.swf
callToActionscript(flashVidSource);
}
ACTIONSCRIPT 3:
import flash.external.ExternalInterface;
//listen for javaScript
ExternalInterface.addCallback("swapVideo", swapVideo);
//set the intial source of videoMc by calling the function and pushing the string
swapVideo("video1");
function swapVideo(str):void
{
trace("swapVideo");
//depending on the string passed from JavaScript, display correct video
//video1
if (str == "video1")
{
//aiello's path
videoMc.source = "video1.flv";
}
//video2 if (str == "video2")
{
//video2's path
videoMc.source = "video2.flv";
}
}
It is not working, PLEASE HELP!
Last edited by developerSpy; 06-29-2012 at 03:29 PM.
|