How come my MovieClip isn't working?
What I'm trying to do is create a series of MovieClips into my flash project (via actionscript) to create a scrolling background. But I'vev run into a strange issue.
For some reason, although I think I am adding the movieclips correctly to the stage, all the variables are set to zero.
Here is the code in my main timeline I am using to create the MovieClips (GrassTile)
var grassHolder:Sprite = new Sprite();
addChild(grassHolder)
for(var i:int = 0;i < 5; i++)
{
grassHolder.addChildAt(new GrassTile(i), i);
}
(and, if you know a working BBCode to show code, it would also help
)
And here is my GrassTile class: I cut out the unimportant stuff. I can add it in later if it is needed.
package {
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.events.Event;
public class GrassTile extends MovieClip
{
private var _root:MovieClip
private var grass:Bitmap;
public var id:int;
public function GrassTile(id:int)
{
this.x = 100
this.id = id;
addEventListener(Event.ADDED_TO_STAGE, onEnterStage);
}
public function updateGrassTiles():void //called from the main timeline
{
this.x = (0 % this.width) + (this.width * (id));
this.y = stage.stageHeight - this.height;
trace(this.width);
trace(this.x); //These traces return only "0" unless it was the last one created
}
private function onEnterStage(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onEnterStage);
_root = MovieClip(root);
grass = _root._resource.GrassImage;
addChild(grass);
}
}
}
As I stated in the code comments, when the GrassTiles are added, every one except the last one added returns 0 for its x and width, and doesn't add the Bitmap image.
Thanks in advance!