TypeError: Error #1010: A term is undefined and has no properties? - actionscript-3

Error:
TypeError: Error #1010: A term is undefined and has no properties. at Untitled_2_fla::MainTimeline/frame1()[Untitled_2_fla.MainTimeline::frame1:4]
Can't seem to figure out what's that about.
Here's my code:
import flash.events.MouseEvent;
btnMc1.txtSourceMc.gotoAndStop();
btnMc1.addEventListener(MouseEvent.ROLL_OVER, over);
btnMc1.addEventListener(MouseEvent.ROLL_OUT, out);
function over(e: MouseEvent) {
btnMc1.buttonMode = true;
btnMc1.gotoAndPlay(1);
}
function out(e: MouseEvent) {
btnMc1.gotoAndPlay(62);
}

You need to create the variable btnMc1, such as var btnMc1 And you're going to have to give it a class such as var btnMc1:
whatEverObjectICreated = new whatEverObjectICreated;

btnMc1.txtSourceMc.gotoAndStop();
Change that to
btnMc1.txtSourceMc.gotoAndStop(1);
Make sure that you've named you MCs correctly. Firstly, go to your stage, and click on btnMc1. Make sure you've name it as such in the properties panel(windows -> properties). Next, double click onto btnMc1 and do the same for txtSourceMc, make sure that it has the correct name. Im assuming that you have txtSourceMc inside btnMc1 on the timeline.
If the problem persists, it is probably because whatever you're loading into btnMc1 or txtSourceMc is too huge. So it cannot instantiate on the frame you're trying to call it in this code, thus it returns as undefined.
To solve this, right click onto btnMc1 from the library and select properties. Then select export for actionscript and make sure that the box for exporting on frame1 is checked. Do the same for txtSourceMc.

Related

typeError: Error #1006: setChildIndex is not a function

Do you know what causes this error?
TypeError: Error #1006: setChildIndex is not a function.
at Function/()[iVision_Game_fla.MainTimeline::frame83:151]
Here's where I think the error occurs...
function dragObject(indx1:int,indx2:int):Function {
return function(event:MouseEvent){
var item:MovieClip=MovieClip(event.currentTarget);
item.startDrag();
var topPos:uint=this.numChildren-1;
var itemSound:Sound = new Sound();
itemSound.load(new URLRequest("sounds/"+dirArray[indx1])+indx2+".mp3"));
if(!activeSound)
{
itemSound.play();
activeSound=true;
}
this.setChildIndex(item, topPos);
}
}
//calling it on another function
var functionOnDrag:Function = dragObject(indexc[count-1],index[count2]);
pb[i].addEventListener(MouseEvent.MOUSE_DOWN,functionOnDrag);
I think scope is the problem here. If the item's parent isn't changing, you can use item.parent.setChildIndex(item, topPos)
Also, before that, topPos:uint = item.parent.numChildren -1;
Update:
To debug further, put a breakpoint on the line of setChildIndex (151). (adding a breakpoint: click to the left of the line number. it will add a little red circle. When code hits this in debug mode it will stop.)
Then go to Debug -> Debug Movie -> Debug
When it stops, open the Debug Panels: Window->Debug Panels->Variables, Window->Debug Panels->Callstack
In the variable panel, you should see all the current variables in the scope. What you are looking for is an issue with the object that setChildIndex is being called on. In this case, the parent of item. You can drill down to see what that is. It should be a DisplayObjectContainer (MovieClip, Sprite, etc...). Item came from event, so i would check event.currentTarget as well. You are basically trying to confirm that at that breakpoint, item exists, it has a parent, and it's parent is a DisplayObjectController. If one of these isn't true, you can track backwards from here why this isn't the case.
TypeError: Error #1006: setChildIndex is not a function
You have created anonymous function, if you want capture this, you could do such construction:
var selfRef:MyClass = this;
Now your handler for the MouseEvent will look:
function dragObject(indx1:int, indx2:int):Function {
return function (event:MouseEvent) {
//Your code
selfRef.setChildIndex(item, topPos);
}
}

Error #1056: Cannot create property *** on ***

I have a weird problem, and I don't know why this is happening.
I have a movieClip with the name of wellcomeMenu. It is exported for AS with the name of WellcomeMenu, and in the document class I do this:
public var _welcome:WellcomeMenu = new WellcomeMenu();
public function MainTest()
{
_welcome.x = stage.stageWidth * 0.5
_welcome.y = stage.y
addChild(_welcome);
}
All simple stuff. Then I go into the WellcomeMenu movieClip and make a shape with the name Box, then I make it a movieClip too, and give its Instance Name the name specialItem.
To sum up: I dynamically call a wellcomeMenu movieclip, which contains another movieClip with an instance name of specialItem. Then I compile and get this error:
ReferenceError: Error #1056: Cannot create property specialItem on WellcomeMenu.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at WellcomeMenu()
at MainTest()
what am I doing wrong?
When I remove its instance name, it shows just fine, but I can't manipulate the movieclip within the WellcomeMenu.
I think the problem is in specialItem attribute in the WellcomeMenu class (by the way, you may have an extra l in there if it's English). If the environment is failing to create the attribute, it is probably already there, but with the wrong permission.
If you declared specialItem manually, make sure it's public and not private (public Sprite specialItem) or else the environment won't have permission to set its value.
Another possible issue is that you declared specialItem manually and still enabled the "automatically declare instance", the environment may try to redeclare the attribute and fail. So either remove the manual declaration or disable that option.
The error can happen if you assign an object of one type to another.
var square:Square = new Square();
square.row = 9; //OK, There is a row property in the Square class
var block:Block = new Block();
square = block; //this is not a compiler error, but probably a mistake
square.row = 0; //error if there is no row property on Block

AS3 Add event listener to a movieclip within a movieclip

I currently have two movieclips one called mcInvFrame, and one called btnCloseInv (It is a movieclip, and I know the naming convention is wrong). btnCloseInv is located inside mcInvFrame. I have two files Inventory.as and my main document class. I can load the mcInvFrame just fine to the stage and everything works as expected. However when I try to access the btnCloseInv movieclip i get errors. Here is the code for Inventory.as I have commented out my most recent failed attempt
package{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Inventory extends MovieClip
{
public var inv:MovieClip = new mcInvFrame;
public function Inventory()
{
addChild(inv);
/*var invClose:MovieClip = inv.btnCloseInv;
invClose.addEventListener(MouseEvent.CLICK, CloseInventory);
function CloseInventory($e:MouseEvent):void
{
this.parent.removeChild(inv);
}*/
}
}
}
What I need to know is can/should i create a variable within inventory.as for the button that I can access from the main document? If so how?
P.S. I have been searching the forums and trying various solutions but I either didn't understand the implementation or they were not suitable for this situation. The most common error I receive is "Error #1009: Cannot access a property or method of a null object reference." Occasionally I will receive an error stating that an object has no properties.
you cant register event on stage.movieclip.movieclip2 , i have tried to do the same thing before, but it wont work, try to create btnCloseInv outside, then use this code
btnCloseInv.x = mcInvFrame.x + numberHere;
btnCloseInv.y = mcInvFrame.y + numberHere2;
if you doesn't want to use this code, AS3 - Button inside MovieClip triggers MC's event
EDIT: if you set mcInvFrame.buttonMode = true it will not work

How to fix AS3 TypeError: Error #1009: Cannot access a property or method of a null object reference?

I am getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Skool_fla::MainTimeline/frame1()[Skool_fla.MainTimeline::frame1:10]
at flash.display::MovieClip/gotoAndStop()
at Skool_fla::MainTimeline/goback()[Skool_fla.MainTimeline::frame2:22]
What is causing this error and how do I fix it?
This is my code for both the frames:
Frame 1: This is the main menu screen where you can access the credit section
import flash.events.MouseEvent;
//setting up the variables
//events
//stop the timeline
stop();
//the play button
play_btn.addEventListener(MouseEvent.CLICK, playani);
function playani(e:MouseEvent)
{
//asking it to progress to the load menu
gotoAndStop(3);
}
//the credits button
credit_btn.addEventListener(MouseEvent.CLICK, creditslide);
function creditslide(e:MouseEvent)
{
//asking it to go the credits frame
gotoAndStop(2);
}
Frame 2: This is where the credits appear
//
//
//all the imports
//events
var credit:credits_bck = new credits_bck ();
var credits_name: credit_nm = new credit_nm ();
var back_butn: back_button = new back_button ();
addChild (credit);
addChild (credits_name);
addChild (back_butn);
back_butn.addEventListener(MouseEvent.CLICK,goback);
function goback(G:MouseEvent)
{
removeChild (credit);
removeChild (credits_name);
gotoAndStop(1);
}
Either play_btn or back_butn is null. Your error message's line numbers don't correspond to your code so it's hard to say. But the gist is you're trying to access a property of something that isn't anything. Check to make sure you're initializing your variables/references properly.
Maybe your problem is Flash bug too.
In my FLA there was a layer with one empty keyframe. If I puted a vector graphics on it, the error was gone. If there was one or multiple MovieClips and there was no vector graphic - the error was there again.
Then I made a new layer and copy pasted all the objects from damaged layer to new and deleted the damaged layer. It solved the problem.
NOTE: Don't copy the keyframes. Only copy the contents.
Now my project is much more complicated and sadly the error came back again.
Test movie frequently and if the error comes back, check the last keyframes and layers you created.

AS3 TypeError: Error #1009

I am trying to create a web application with multiple scenes, the error appears when I try to access the next scene with a button I created that contains multiple EventListeners for animation purposes.
The Button did bring me to the next scene, but the error still occurs. After tracing and debugging, the error seems to occur at the Mouse_Out event.
I am still very new to AS3, so can someone please explain to me where my code went wrong and if possible, correct the error for me or is there a better way of writting the code? Thanks in advance.
The Error Involved:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.transitions::Tween/setPosition()
at fl.transitions::Tween/set position()
at fl.transitions::Tween()
at Portfolio_fla::MainTimeline/about_btnOut()
My Code:
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
about_btn.buttonMode = true;
about_btn.mouseChildren = false;
about_btn.alpha = 0.3;
about_btn.addEventListener(MouseEvent.MOUSE_OVER, about_btnOver);
function about_btnOver(event:MouseEvent):void
{
var AboutAlphaOver:Tween = new Tween(about_btn,"alpha",Regular.easeIn,0.3,1,0.1,true);
}
about_btn.addEventListener(MouseEvent.MOUSE_OUT, about_btnOut);
function about_btnOut(event:MouseEvent):void
{
var AboutAlphaOut:Tween = new Tween(about_btn,"alpha",Regular.easeIn,1,0.3,0.1,true);
}
about_btn.addEventListener(MouseEvent.CLICK, about_btnClick);
function about_btnClick(event:MouseEvent):void
{
gotoAndPlay(1,"About");
}
Try to change your Tween code:
var AboutAlphaOut:Tween = new Tween(about_btn,"alpha",Regular.easeIn,1,0.3,0.1,true);
To:
var AboutAlphaOut:Tween = new Tween(event.currentTarget,"alpha",Regular.easeIn,1,0.3,0.1,true);
I'm not sure if it will work (I'm not too familiar with Flash IDE), but I think it's possible that you are getting error because other scene doesn't have a reference to a button. With event.currentTarget, you will search for reference in the event, so it should find it in any case.
BTW: You shouldn't name your variables starting by capital letter. That way you will more easily distinguish objects from classes.