dr_tchock
June 18th, 2009, 11:30 AM
Simple question, I hope.
I have some MovieClips on the stage which I want to loop through and convert them into a custom (Dragger) class (if their name starts with "drag_");
I usually pass each one as a parameter to the constructor of the Dragger class and then add them as a Child but I'm convinced there is a better way.
Can't I just cast them as Dragger?
this is what I've tried to do, but it doesn't work
private function initDraggers():void
{
var activity = activitiesArr[currActivity]; // gets current activity from array
draggersArr = []; // creates array
var len: int = activity.numChildren; // int for loop iteration
for (var i:int= 0; i < len; i++)
{
if (activity.getChildAt(i).name.indexOf("drag_") >= 0) // if MovieClip is intended to be a Dragger
{
var dragger: Dragger = activity.getChildAt(i) as Dragger;
}
}
}
this doesn't work
I have some MovieClips on the stage which I want to loop through and convert them into a custom (Dragger) class (if their name starts with "drag_");
I usually pass each one as a parameter to the constructor of the Dragger class and then add them as a Child but I'm convinced there is a better way.
Can't I just cast them as Dragger?
this is what I've tried to do, but it doesn't work
private function initDraggers():void
{
var activity = activitiesArr[currActivity]; // gets current activity from array
draggersArr = []; // creates array
var len: int = activity.numChildren; // int for loop iteration
for (var i:int= 0; i < len; i++)
{
if (activity.getChildAt(i).name.indexOf("drag_") >= 0) // if MovieClip is intended to be a Dragger
{
var dragger: Dragger = activity.getChildAt(i) as Dragger;
}
}
}
this doesn't work