Hey there!
Ok, so I’m pretty new to AS3, and I have a question.
Here’s the code:
import flash.filters.GlowFilter;
addEventListener(Event.ENTER_FRAME, createNewBox);
addEventListener(MouseEvent.MOUSE_DOWN, startTheDrag, false, 0, true);
addEventListener(MouseEvent.MOUSE_UP, stopTheDrag, false, 0, true);
const boxNum = 10;
var box:MovieClip;
var newBox:MovieClip;
var boxIndex:int;
var newBoxIndex:int = 0;
var alphaJump:Number = 1/(boxNum);
var oldAlpha:Number;
var glow:GlowFilter = new GlowFilter(0xFFCC00,1,26,26,1.3,3);
function createNewBox(evt:Event): void {
if(newBoxIndex < boxNum) {
var newBox:MovieClip = new BOX();
addChildAt(newBox, newBoxIndex);
with(newBox) {
x = y = (newBoxIndex * 35) + 50;
name = "box"+(newBoxIndex+1);
labelz.text = name.toUpperCase();
buttonMode = true;
alpha = 0 + ((newBoxIndex+1) * alphaJump);
}
newBoxIndex++;
}
}
function startTheDrag(evt:MouseEvent):void {
box = evt.target as MovieClip;
boxIndex = getChildIndex(box);
setChildIndex(box, numChildren-1);
box.gotoAndPlay(2);
box.startDrag();
box.filters = [glow];
oldAlpha = box.alpha;
box.alpha = 1;
}
function stopTheDrag(evt:MouseEvent):void {
evt.target.stopDrag();
box = evt.target as MovieClip;
box.gotoAndPlay(11);
setChildIndex(box, boxIndex);
box.filters = null;
box.alpha = oldAlpha;
}
If I click on the text label, instead of the box itself, I get the following error message:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display:DisplayObjectContainer/getChildIndex()
at boxes_fla::MainTimeline/startTheDrag()
ReferenceError: Error #1069: Property stopDrag not found on flash.text.TextField and there is no default value.
at boxes_fla::MainTimeline/stopTheDrag()
The text label is inside the target, so why am I not able to drag the object if I happen to click on the area of the textbox?
Thanks in advance,
***Confused newbie