I'm trying to name the instances of MovieClips that I dynamically load.
I tried doing this:
comp = new Comp();
// and also tried doing this--> var comp:MovieClip = new Comp();
comp.name = "comp"; // comp is the name I want the instance to be
BUT in the OUTPUT Window:
ReferenceError: Error #1056: Cannot create property comp on ToggleTest.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at ToggleTest()
This is the code that I have in my ActionScript file: package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class ToggleTest extends MovieClip
{
var comp:MovieClip;
public function ToggleTest()
{
comp = new Comp();
//var comp:MovieClip = new Comp();
comp.name = "comp";
comp.addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
comp.addEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
comp.addEventListener(MouseEvent.CLICK, toggleClick);
comp.bstate = 0;
comp.buttonMode = true;
// Add Movie Clip "buttons" to stage
stage.addChild(comp);
comp.x = 120;
comp.y = 130;
// calls function frameloop
stage.addEventListener(Event.ENTER_FRAME, frameloop);
}
// function rolloverToggle
function rolloverToggle(e:MouseEvent) {
if (e.currentTarget.currentFrame == 1)
e.currentTarget.gotoAndStop(2);
if (e.currentTarget.currentFrame == 3)
e.currentTarget.gotoAndStop(4);
}
// function rolloutToggle
function rolloutToggle(e:MouseEvent) {
if (e.currentTarget.currentFrame == 2)
e.currentTarget.gotoAndStop(1);
if (e.currentTarget.currentFrame == 4)
e.currentTarget.gotoAndStop(3);
}
// function toggleClick
function toggleClick(e:MouseEvent) {
var houseArray:Object = {lightA: 1,
lightB: 1,
lightC: 1,
lightD: 1,
lightE: 1,
comp: 2,
tv: 3,
stove: 4,
laundry: 5};
var powerData:int = houseArray[e.currentTarget.name.toLowerCase()];
trace("movieClip Instance Name = " + e.currentTarget);
trace(powerData);
trace(houseArray[0]);
// how to find out which object selected
if (e.currentTarget.currentFrame == 2)
{
e.currentTarget.gotoAndStop(3);
e.currentTarget.bstate = 1;
}
if (e.currentTarget.currentFrame == 4)
{
e.currentTarget.gotoAndStop(1);
e.currentTarget.bstate = 0;
}
}
function frameloop(e:Event)
{
var outtext:String="";
outtext += comp.bstate +", ";
outfield.text = outtext;
}
}
}