Hello everybody, hopefully somebody will be able to help me.
I have an array with some indexes inside and I want to pass one of those index as a addChild parameter. If I type it (i.e. Tambor1_mc.addChild(atunIcon); then it´s fine, I can see the mc on the stage. But if I try to pass it dynamically, I get a #1034 error (can´t convert “tunaIcon” in flash.display.DisplayObject.
If I try Tambor1_mc.addChild(arrayTambores.bigArrayTambor1[0] as DisplayObject); I get a #2007 error (yhe value of the child parameter must be different from null).
Any ideas? Thanks in advance!
I have this in Main.as:
package
{
import flash.display.*;
import flash.events.*;
import flash.utils.*;
{
public class Main extends MovieClip
{
public function Main():void
{
var Tambor1_mc:MovieClip = new MovieClip();
var atunIcon:atun = new atun();
var cafeIcon:cafe = new cafe();
// BUTTON
makeButton(my_mc, my_mc_click);
function my_mc_click(evt: MouseEvent):void
{
Tambor1_mc.addChild(arrayTambores.bigArrayTambor1[0]);
stage.addChild(Tambor1_mc);
}
function makeButton(which_mc: MovieClip, clickFunction: Function):void
{
which_mc.buttonMode = true;
which_mc.useHandCursor = true;
which_mc.mouseChildren = false;
which_mc.addEventListener(MouseEvent.CLICK, clickFunction);
}
}
}
}
};
In arrayTambores.as, I have:
package
{
public class arrayTambores
{
public static var tempArray: Array = new Array();
public static var bigArrayTambor1: Array = new Array();
public static var bigArrayTambor2: Array = new Array();
public static var bigArrayTambor3: Array = new Array();
public static var randomPos:Number = 0;
public static var a:int = 0;
public static var z:int = 0;
for (a = 0; a < 13; a++)
{
tempArray.unshift("atunIcon");
}
for (a = 0; a < 13; a++)
{
tempArray.unshift("cafeIcon");
}
public function arrayTambores()
{
}
}
}
(The code is larger than what I paste here, but the rest of it seems to work fine, so I didn´t want to get messy here)