As3 Stage Typeerror Error #1009
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the
Type Error 1009
workings and policies of this site About Us Learn more about type error 1009 cannot access a property Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Typeerror: Error #1009: Cannot Access A Property Or Method Of A Null Object Reference. Flash
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. cannot access a property or method of a null object reference. as3 Join them; it only takes a minute: Sign up TypeError: Error #1009 - AS3 up vote -1 down vote favorite I'm getting this error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Lemonade_fla::MainTimeline/frame3()[Lemonade_fla.MainTimeline::frame3:48] From this snippet of code: buy_sugar.addEventListener(MouseEvent.CLICK, buysugar); function buysugar(event:MouseEvent):void{ if (cash1>=0.50){ buy.play(); cash1 = cash.text.text; cash1 = cash1 - 0.25; sugar = sugar_count.text; sugar=sugar+16; } } Does anyone have any ideas of why? actionscript-3 share|improve this question asked Mar 26 '11 at 17:54 Noah R 1,330133358 Which of those is line 48? When you find line 48, one of those objects on it will be null. Of the 10 lines of code you've listed, that could possibly be... buy_sugar, buy, cash, cash.text, or sugar_count. –scriptocalypse Mar 26 '11 at 18:03 The first line is. –Noah R Mar 26 '11 at 18:06 then buy_sugar is null. Is it a movieclip that you believe to be on the timeline when you call buy_sugar.addEventListener? –scriptocalypse Mar 26 '11 at 18:08 Yes, it's a movieclip with the instance name buy_sugar. Why? –Noah R Mar 26 '11 at 18:11 It's not actually there when you're calling buy_sugar.addEventListener. That's the problem. Try this on the line right above the call to addEventListener ... trace(buy_sugar); –scriptocalypse Mar 26 '11 at 18:13 | show 5 more comments 3 Answers 3 a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping http://stackoverflow.com/questions/5444120/typeerror-error-1009-as3 each other. Join them; it only takes a minute: Sign up AS3 - TypeError: Error #1009 up vote -1 down vote favorite I'm trying to create a system that puts each block in a block Array which I can use to easily add blocks to the stage via XML, however I'm getting [Fault] exception, information=TypeError: Error #1009: Cannot http://stackoverflow.com/questions/18981200/as3-typeerror-error-1009 access a property or method of a null object reference. When it initializes the 'blockStone'. Here's my main Block class, each block is initialized here. package com.snakybo.platformengine.block { import flash.display.MovieClip; public class Block extends MovieClip { public static var blockList:Array = []; public static const blockStone:Block = (new BlockStone(0)); public var blockID:int; private var mc:MovieClip; public function Block(blockID:int, mc:MovieClip) { if (blockList[blockID] != null) { throw new Error("Slot " + blockID + " is already occupied by " + blockList[blockID] + " when adding " + this); } else { blockList[blockID] = this; this.blockID = blockID; this.mc = mc; mc.x = 100; mc.y = 100; addChild(mc); } } } } Here's the BlockStone class: package com.snakybo.platformengine.block { public class BlockStone extends Block { public function BlockStone(blockID:int) { super(blockID, new stone()); } } } FlashDevelop refers to this line when it errors: public class BlockStone extends Block { Here's the stack trace: TypeError: Error #1009: Cannot access a property or method of a null object reference. at global$init()[C:\Users\Kevin\Desktop\Extra\Code\Actionscript\PlatformEngine\src\com\snakybo\platformengine\block\BlockStone.as:3] at com.snakybo.platformengine.block::Block$cinit() at global$i
other Adobe products. Flash Player Runtime Errors and How to Fix Them The following lists common runtime errors found with Flash Player and what you can do to fix them. Also available, Compiler Errors. TypeError: Error #1009 TypeError: Error #1009: Cannot access a property or method of a null object reference. This error occurs when you attempt to access a property or call a method (function) from an object variable that has no value (undefined) or has a null value. If the object is null, it has no value itself meaning it cannot contain any properties. The following example would be a situation where the error would occur: var mySprite:Sprite; // null since not defined trace(mySprite.x); // Error #1009 Because the mySprite variable is null, accessing mySprite.x would be the same as null.x which is not possible, thereby creating the error condition. Note that this behavior is new to ActionScript 3.0. In ActionScript 2.0 and 1.0, doing this would cause a silent failure and return a value of undefined. Usually when this error occurs, it means an error in your code logic. You're code is assuming an object exists when it does not. That is something you will have to identify and fix. This can sometimes be difficult because of the error's ambiguous text; it does not specify what specific object the error is in reference to. However, if you test a debug version of your project in your IDE, it will tell you. Debugging in Adobe Flash Professional: From the File menu, select Debug > Debug Movie. Debugging in Adobe Flash Builder: From the File menu, select Run > Debug [ProjectName]. When debugging (in either Flash Pro or Flash Builder), a Debug version of your project which will include more information about code execution that can help better identify errors. When the error occurs, code execution will pause and the line of code with the error will be pointed out in the code view. Additionally, the Variables panel can be used to inspect the values of the objects and prope