Flash Professional Error 2006 - actionscript-3

I have looked over this and I must be blind as I cannot see what the problem is. I looked a bit online and tried to modify it to work, but no luck.
function dragTheObject(event:MouseEvent):void {
var item:MovieClip = MovieClip(event.target);
item.startDrag();
var topPos:uint = (item, numChildren > 0 ? numChildren-1 : 0);
this.parent.setChildIndex(item, topPos);
}

The AS3 #2006 runtime error ( RangeError: Error #2006: The Supplied Index is Out of Bounds ) is fired by this line :
this.parent.setChildIndex(item, topPos);
because your trying to set an index to your item object which is greater than (or equal to) the DisplayObjectContainer's (this.parent) numChildren property.
So to put your object on the top, you can simply do :
function dragTheObject(event:MouseEvent):void
{
var item:MovieClip = MovieClip(event.target);
item.startDrag();
item.parent.setChildIndex(item, item.parent.numChildren - 1);
}
Hope that can help.

Related

Can't create array of arrays

I'm trying to create array of arrays (like a 2d array) however I'm getting error:
TypeError: Error #1006: value is not a function.
Here's my code:
I'm using Flash Professional CC 2015. How can I fix this error?
EDIT: Here's the full function:
function CreateMainMenu(xPos:Number, yPos:Number, depth:int, menu_xml:XML):void {
// Generate menu list
var arr:Array = new Array();
addChild(mainmenu_mc);
mainmenu_mc.x = xPos;
mainmenu_mc.y = yPos;
setChildIndex(mainmenu_mc, depth);
var num:int = 0;
for each (var tempNode:XML in menu_xml.elements()) {
var arr2:Array = new Array();
arr2.push(tempNode);
arr2.push("menu");
arr[num].push(arr2); // It gives error
num++;
}
trace (arr);
// GenerateMenu(this, "mainmenu_mc", xPos, yPos, depth, arr);
}
The first line number is 58, the last one is 79.
I'm getting this error:
TypeError: Error #1010: A term is undefined and has no properties.
at xmlmenu_05_fla::MainTimeline/CreateMainMenu()[xmlmenu_05_fla.MainTimeline::frame1:72]
at xmlmenu_05_fla::MainTimeline/processXML()[xmlmenu_05_fla.MainTimeline::frame1:118]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
The problem is that you never add anything to arr.
You create the Array here:
var arr:Array = new Array();
but the only time you interact with it is the line that gives you the error:
arr[num].push(arr2); // It gives error
You are trying to access an element here, but you never added anything to the array.
Your variables names are not very descriptive and you likely got lost in this mess:
var arr2:Array = new Array();
arr2.push(tempNode);
arr2.push("menu");
arr[num].push(arr2); // It gives error
num++;
I cannot tell what your intentions are here. IF you just want to add arr2 as the next element, use push, there's no need for num here.
If you write code with meaningful variables names it's easier to keep track of your own code.

cannot convert flash.display::Stage#2a2cdf99 to flash.display.MovieClip?

So I'm creating a platform game in Actionscript 3.0, trying to call a function that spawns blocks based on an array. The code is in a 'Game' class and is directed towards a movieclip on my .fla
When it is ran I get the error:
"cannot convert flash.display::Stage#2a2cdf99 to flash.display.MovieClip."
Here's the code:
public function GameScreen(stageRef:Stage = null )
{
this.stageRef = stageRef;
btnReturn.addEventListener(MouseEvent.MOUSE_DOWN, returnMainMenu, false, 0, true);
mcMain.addEventListener(Event.ENTER_FRAME, moveChar);
this.addEventListener(Event.ENTER_FRAME, createLvl);
this.stageRef.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
this.stageRef.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
this.stageRef.addChild(blockHolder);
}
And
private function createLvl(event:Event):void
{
var lvlArray:Array = MovieClip(root)['lvlArray' +lvlCurrent];
var lvlColumns:int = Math.ceil(lvlArray.length/16);
for(var i:int = 0;i<lvlArray.length;i++){
if(lvlArray[i] == 1){
if(i/lvlColumns == int(i/lvlColumns)){
row ++;
}
var newBlock:Block = new Block();
newBlock.graphics.beginFill(0xFFFFFF);
newBlock.graphics.drawRect(0,0,50,50);
newBlock.x = (i-(row-1)*lvlColumns)*newBlock.width;
newBlock.y = (row - 1)*newBlock.height;
blockHolder.addChild(newBlock);
} else if (lvlArray[i] == 'MAIN'){
mcMain.x = (i-(row-1)*lvlColumns)*newBlock.width;
mcMain.y = (row-1)*newBlock.height;
}
}
row = 0;
}
Please help =(
Thanks!
First of all:
Turn on "permit debugging" in your publish settings. This will give you line numbers with your errors, so you can determine the exact location of your error.
Post the entire stack trace. That error by itself is not a lot to go on.
Given the error and the code you've posted, the error must be caused by your use of MovieClip(root). The root property does not always point to the main timeline in Flash, it will point to the Stage if the display object is added directly to the stage. For example:
trace(stage.addChild(new Sprite()).root) // [object Stage]
Documentation on root: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#root

Possible misuse of evt.target.name. "Error #1010: A term is undefined and has no properties."

So far this program is supposed to make an child object visible when the parent object is moused over, but I can't seem to get it to work. I'm in a little over my head here. Here's my code:
var iconCompArray:Array = new Array();
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMouse);
addIcons();
function addIcons():void
{
var iconComp:IconComp = new IconComp();
iconComp.x = stage.stageWidth/4;
iconComp.y = stage.stageHeight/4;
iconComp.iconImage.gotoAndStop(2);
iconComp.iconHighlight.visible = false;
iconComp.iconTitle.text = "Program X";
iconCompArray.push(iconComp);
addChild(iconComp);
}
function moveMouse(evt:MouseEvent):void
{
for (var i:int = 0; i < iconCompArray.length; i++)
{
if (evt.target.name == iconCompArray[i])
{
iconCompArray[i].iconHighlight.visible = true;
}
}
}
A new "iconComp" is pulled from the library and added to the stage through the iconCompArray. The idea was that when you mouse over the icon, a blue box would appear around it (iconHighlight.visible). But for some reason, what I have here doesn't work. I think I may have used evt.target.name incorrectly but I can't find a solution. Here's the error message that appears in the output:
TypeError: Error #1010: A term is undefined and has no properties.
at as3_fla::MainTimeline/addIcons()
at as3_fla::MainTimeline/frame1()
From the error you get the problem seems to be in the addIcons functions. You should check that the name of all your movie clip's childs is correct. The movie clip's property mouseChildren should be set to false. Also, it would be probably better if you use MOUSE_OVER and MOUSE_OUT events instead of MOUSE_MOVE.
function addIcons():void
{
var iconComp:IconComp = new IconComp();
iconComp.x = stage.stageWidth / 4;
iconComp.y = stage.stageHeight / 4;
iconComp.iconImage.gotoAndStop(2);
iconComp.iconHighlight.visible = false;
iconComp.iconTitle.text = "Program X";
iconComp.mouseChildren = false;
iconComp.addEventListener(MouseEvent.MOUSE_OVER, onIconOver);
iconComp.addEventListener(MouseEvent.MOUSE_OUT, onIconOut);
iconCompArray.push(iconComp);
addChild(iconComp);
}
And the event listeners should look like this:
function onIconOver(evt:MouseEvent):void {
IconComp(evt.target).iconHighlight.visible = true;
}
function onIconOut(evt:MouseEvent):void {
IconComp(evt.target).iconHighlight.visible = false;
}
You can also see the line of code that gives you that error if youy publish the swf in debug mode (Ctrl+Shift+Enter).

Remove the clicked objects

I'm trying to remove the array objects that are being clicked and add them into another array to display them else where. I posted the current code.
I think the problem maybe with .currentTarget. I tried replacing the .currentTarget to .target but the function wasn't getting past this line : if (socket_Array[i] == in_event.target) (in this version its .currentTarget, I am just saying when I tried changing it to .target)
The error I get is this:
TypeError: Error #1034: Type Coercion failed: cannot convert []#2c2a8f11 to flash.display.DisplayObject.
Function that creates the objects:
function createSockets():void
{
var socket_one:socket = new socket ();
var socket_two: socketyellow = new socketyellow ();
var socket_three: socketdarkorange = new socketdarkorange ();
var socket_four: socketlightgreen= new socketlightgreen ();
var socket_five: socketpurple = new socketpurple ();
var socket_six: socketdarkgreen = new socketdarkgreen ();
socket_Array.push(socket_one, socket_two,socket_three, socket_four, socket_five, socket_six);
for (var i:int=0; i<socket_Array.length; i++)
{
addChild(socket_Array[i]);
socket_Array [i].x = socket_x_position;
socket_Array [i].y = socket_y_position;
socket_Array[i].addEventListener(MouseEvent.MOUSE_DOWN, removeItemOnClick);
}
temp_update ();
}
Function that is suppose to get rid of the object clicked and add it to an array.
function removeItemOnClick(in_event:MouseEvent):void
{
var i:int = 0;
for (i=0; i<socket_Array.length; i++)
{
if (socket_Array[i] == in_event.currentTarget)
{
trace ("it goes here");
var removed = socket_Array.splice(i, 1);
trace (removed);
trace (socket_Array );
var drop:Sprite = in_event.currentTarget as Sprite;
removeChild (drop);
removedItem[removedItem.length] = removed;
createremovedItem ();
trace (removedItem);
updateDisplay ();
choice_updateDisplay ();
}
}
}
var removedItem_position = 0
function createremovedItem () {
for (removedItem_position; removedItem_position<removedItem.length; removedItem_position++){
addChild (removedItem [removedItem_position]);
}
}
First of all, .currentTarget is correct.
Secondly, there's no point in calling removeChild() and then calling addChild(). The net effect of both calls is nothing.
Almost all of the code in the second function is unnecessary. Here's a shorter version:
function removeItemOnClick(in_event:MouseEvent):void {
var index:int = socket_Array.indexOf(in_event.currentTarget);
var drop:Sprite = socket_Array.splice(index,1) as Sprite;
removedItem.push(drop);
updateDisplay();
choice_updateDisplay();
}
If you want to display the new item elsewhere, just change drop.x and drop.y.
As the error suggests it looks like it is problem with type coercion.
Try to replace the condition of your if statement with this:
if (DisplayObject(socket_Array[i]) == DisplayObject(in_event.currentTarget))
In case this is not working your might have more information while debugging by storing the two objects you want to compare into temporary variables

TypeError: Error #1010 in AS3 in accordion

I had created Accordion in flash. and I am getting following error
TypeError: Error #1010: A term is undefined and has no properties.
at accordionSub_fla::accordionMain_1/mouserOver()
But, this error is only reflecting on Panel3, I have 9 Panels, all of them are working fine except Panel3 and this Panel3 is not opening only. Below is the code of function
function mouserOver(e:MouseEvent):void {
var overed:MovieClip = MovieClip(e.target);
for(var i:int=0; i<numChildren; i++)
{
var mc:MovieClip = MovieClip(getChildAt(i));
if(mc.props.ind <= overed.props.ind)
{
TweenLite.to(mc, 1, {x:mc.props.lx, ease:Expo.easeOut});
var request:URLRequest = new URLRequest(mc.props.links);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, urlAction);
function urlAction(evt:TimerEvent)
{
navigateToURL(request, 'myFrame');
}
}
else
{
TweenLite.to(mc, 1, {x:mc.props.rx, ease:Expo.easeOut});
}
}}
Any immediate response will be helpful. Thanks.
Where is numChildren's value come from?
check these lines:
var mc:MovieClip = MovieClip(getChildAt(i));
if(mc.props.ind <= overed.props.ind)
mc can be null in some condition, and access its property will fire an error.
I got an answer.. there is no error on the code. actually when-ever I am clicking on button it gives an error and I made Panel3's heading as button, so it was firing an error. Now, I made it simple text field, now the problem is solved.
anyways, thanks Frank