|
-
TypeError: Error #1010: A term is undefined and has no properties.
Please help, I'm an actionscript noob.
I have been getting the following error message with my code:
TypeError: Error #1010: A term is undefined and has no properties.
When I rollover the movieclip one or two the error occurs. Here is my code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.DisplayObject;
var StateArray:Array = [one, two];
for (var i:int=0;i<2;i++)
{
StateArray[i].addEventListener( MouseEvent.ROLL_OUT, mouseCall );
StateArray[i].addEventListener( MouseEvent.ROLL_OVER, mouseCall );
StateArray[i].addEventListener( MouseEvent.CLICK, mouseCall );
StateArray[i].buttonMode = true;
trace(StateArray[i]);
function mouseCall( event:MouseEvent ):void
{
switch( event.type )
{
case MouseEvent.ROLL_OVER:
new Tween(StateArray[i], "scaleX", Strong.easeOut, StateArray[i].scaleX, 1.1, .50, true );
new Tween(StateArray[i], "scaleY", Strong.easeOut, StateArray[i].scaleY, 1.1, .50, true );
addChild(StateArray[i]);
break;
case MouseEvent.ROLL_OUT:
new Tween(StateArray[i], "scaleX", Strong.easeOut, StateArray[i].scaleX, 1.0, .50, true );
new Tween(StateArray[i], "scaleY", Strong.easeOut, StateArray[i].scaleY, 1.0, .50, true );
break;
case MouseEvent.CLICK :
//targetFrame = event.target.name;
removeChild(StateArray[i]);
gotoAndStop(2);
break;
}
}}
Any help would be greatly appreciated
Last edited by nordberg60; 09-04-2010 at 11:34 PM.
-
Senior Member
addchild the object before applying the tween to it.
If you like me, add me to your friends list  .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter: 
-
addChild the object
Thank you for your reply, however, I tried to addChild to the object and still get another error and I still get an error message that the
" Parameter child must be non-null."
&
"A term is undefined and has no properties."
Any idea what else I am missing?
Thanks again
-
M.D.
Its not a smart way to use a function like that. It looks like you're trying to create a new function on every loop iteration and sort of keep that function in the state when it was created which isn't possible. Whats undefined is this: "StateArray[i]" as the variable "i" is not being saved to the function, when this function runs the value of "i" is 2. StateArray[2] is undefined. "i" is a variable which exists in the scope of the loop, not the function. So when your loop finishes and the mouse event occurs "i" is 2 because thats the size it was when the loop ended.
Here's a working version:
Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.DisplayObject;
var StateArray:Array=[one,two];
for (var i:int=0; i<2; i++) {
var state:MovieClip = StateArray[i];
state.addEventListener( MouseEvent.ROLL_OUT, mouseCall );
state.addEventListener( MouseEvent.ROLL_OVER, mouseCall );
state.addEventListener( MouseEvent.CLICK, mouseCall );
state.buttonMode=true;
trace(state);
}
function mouseCall( event:MouseEvent ):void {
var state:MovieClip = event.currentTarget as MovieClip;
switch ( event.type ) {
case MouseEvent.ROLL_OVER :
new Tween(state,"scaleX",Strong.easeOut,state.scaleX,1.1,.50,true);
new Tween(state,"scaleY",Strong.easeOut,state.scaleY,1.1,.50,true);
addChild(state);
break;
case MouseEvent.ROLL_OUT :
new Tween(state,"scaleX",Strong.easeOut,state.scaleX,1.0,.50,true);
new Tween(state,"scaleY",Strong.easeOut,state.scaleY,1.0,.50,true);
break;
case MouseEvent.CLICK :
//targetFrame = event.target.name;
removeChild(state);
gotoAndStop(2);
break;
}
}
The mouse code is separated from the loop as you don't need to create that function on every iteration.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|