Work Around Mr. bugg

Standard

OK, after a few minutes on trying to making AS execute in a SWF file after the SWF file has being loading into flex, I abandoned my methodology and devised a work around the problem. I created the SWF file with no AS script embedded and loaded it into flex using the loader component. Using the “content” variable of the loader component (which points to the SWF file ) I accessed the movieClips in my SWF file and manipulate them with AS in my mxml file.

———————————————————————————–
Here is the code to the mxml file

||

||
|<|–[CDATA[
var interval:Number ;
var myDate:Date;
function Initial()
{
setInterval(this,”startclock”,1000);
}

function startclock() {
myDate = new Date();
Clock.content.clock_mc.Hourhand._rotation = myDate.getHours()*30 +(myDate.getMinutes()/2);
Clock.content.clock_mc.Minutehand._rotation = myDate.getMinutes()*6+(myDate.getSeconds()/10); Clock.content.clock_mc.Secondhand._rotation = myDate.getSeconds()*6;
} ]]–|>|
||

||

||
————————————————————————————-
Im sure the code is self explanatory but ….for those who don’t understand

when the application is initialized, it executes the Initial() function which in turn set a 1 second loop execution interval on the function “startclock” . This is where the actual work happens. My clock.swf file contains clock_mc which in turn contain Hourhand, Minutehand and Secondhand movieclip. Accessing my moveiclip through Clock.content.clock_mc.Movieclip_name, every second execution of the startclock function set the time in the Clock component. Hope this helps.

PS: replace |<| with | with /> if you want to use the code

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s