Changing background image of a MovieClip in AS3
I have the following package
package{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.*;
import flash.display.Loader;
import flash.net.*;
public class rotatorButton extends MovieClip{
private var timer:Timer;
private var buttonNum:int;
private var lapse:int;
private var ticks:int;
public function rotatorButton(num:int,newLapse:int,newX:int,newY:int){
buttonNum = num;
lapse = newLapse;
width = 50;
var t:TextField = new TextField();
/* textFormat code
x = newX;
y = newY;
addChild(t);
timer = new Timer((lapse/40),0);
timer.addEventListener(TimerEvent.TIMER,fillBackground);
}
public function getButtonNum()
{
return buttonNum;
}
public function loadItem():void{
timer.start();
ticks = 0;
}
private function fillBackground(e:TimerEvent):void{
ticks += 1;
if(ticks <= 20)
{
var loadit = new Loader;
addChild(loadit);
loadit.load(new URLRequest("button" + ticks + ".png"));
}
}
}
}
Not sure how clear that is but what I'm trying to do is this ....
1. The class instantiates and adds a number as text on top of the image that I created the MovieClip class from
2. As the main class of the fla rotates images it calls the loadItem() function of each cooresponding button.
3. That function starts the timer and, on each tick of the timer, the background image changes.
What is happening right now with this code is that the new image (that I want to be the background image behind the text) is coming in on top of the text.
Is there a way to simply replace the image currently loaded into the MovieClip.
Thanks in advance.