I've created a Flash Animation (CS5, ActionScript 3) and converted it to SWF. The flash animation needs the values of 3 variables (defined in the swf timeline) BEFORE it starts running in my Flex application. I've embedded the swf file using swfloader in Flex, but I need to pass the parameters from Flex into Flash before the animation starts. How do I do this?
The way I have my flex code setup below, the variables are not being updated. I get an exception every time it gets to the changeParams function because it can't find "Type", "Num1", etc.
Part of My flash code:
//These 3 variables need to be populated via Flex BEFORE the animation starts...
var Num2:int;
var Num1:int;
var Type:String;
var whichNumber:int;
var frameNumber:int;
function playMe():void {
switch (Type) {
case 'type1':
gotoAndPlay(16);
break;
case 'type2':
frameNumber = 27;
whichNumber = 1;
gotoAndPlay(frameNumber);
break;
case 'type3':
frameNumber = 29;
whichNumber = 1;
gotoAndPlay(17);
break;
case 'type4':
whichNumber = 1;
break;
}
}
My flex code:
public function changeParams():void {
idAnimation.content["Type"] = 'type1';
idAnimation.content["Num1"] = 6;
idAnimation.content["Num2"] = 30;
trace ("Type= " + idAnimation.content["Type"]);
trace ("Num1= " + idAnimation.content["Num1"]);
trace ("Num2= " + idAnimation.content["Num2"]);
}
]]>
</mx:Script>
<mx:SWFLoader id="idAnimation" source="animation.swf" init="changeParams()" />