SEARCH YOUR SOLUTION HERE  

Stage and Keyboard getting TypeError: Error #1009:

Trying to hook up a keyboard listener to the stage but am getting a runtime error. Spent over an hour trying to figure out what's going on, but from everything I've seen (online and in a reference book) the stage should not be null, but it is.
Code: package ghg.system { import flash.display.*; import flash.events.Event; import flash.events.KeyboardEvent; public class Input extends Sprite { public function Input() { super(); stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener ); stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener ); } private function keyDownListener( e:KeyboardEvent ) :void{} private function keyUpListener( e:KeyboardEvent ) :void{} } } The specific run-time error is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ghg.system::Input()
at Main()
at russianreactor_fla::MainTimeline/frame1()

Any idea why the stage is null
Do I have to do some type of initialization on it

Posted On: Thursday 25th of October 2012 11:05:45 PM Total Views:  337
View Complete with Replies




Related Messages:

How to add a child to a particular scene's stage?   (352 Views)
I have to scenes, dashboard and game. I want to add a child just to game's stage. Can someone tell me the syntax for this
How Do I add contextMenu to stage?   (134 Views)
So in AS2 you could add a contextMenu for the whole movie like this: Code: var newMenu = new ContextMenu(); newMenu.hideBuiltInItems(); _root.menu = newMenu; There is no _root in AS3. So in my Document class I tried this: Code: stage.contextMenu = new ContextMenu(); Which results in this error: Error: Error #2071: The Stage class does not implement this property or method. at Error$/throwError() at flash.display::Stage/set contextMenu() I have also tried just adding items to stage.contextMenu but that didn't work either. I also added a custom context menu to my Document class but that doesn't work for the whole movie. So does anyone know if there is something I can do to set the contextMenu for the whole movie
this.(stage/root) isn't mouseable?   (89 Views)
Questions are easy (Have I lost my mind) -- and i don't think this (scuse the pun) gets much easier. Ahh but the answer... 400x500 stage, single layer (or with the AS in a 2nd layer) with a jpg (80x250) centered on stage and symbol'd to graphic (or mc). why doesn't the following function traces appear when mousing in and out of the stage: // or MOUSE_HOVER this.addEventListener(MouseEvent.ROLL_OVER,MOver); this.addEventListener(MouseEvent.ROLL_OUT,MOut); function Mover(event:MouseEvent) { trace("In Mouse"); } function CloseDoor(event:MouseEvent) { trace("out mouse"); } trace("loaded"); So obviously a newb..
Accessing stage objects with in a class   (104 Views)
Sorry if this quesiton has been posted, but I don't think I am using the right terms to search. I am trying to learn how classes can interact with each other and I came across a problem I can't solve. On my stage I have a MovieClip called "myMovieClip". Toplevel.as: Code: package edu.mydomain{ import flash.display.Sprite; public class TopLevel extends Sprite { public function TopLevel() { var temp:SecondClass = new SecondClass; } } } SecondClass.as: Code: package edu.mydomain{ import flash.display.*; class SecondClass extends MovieClip{ public function SecondClass(){ root.myMovieClip.x = 0; } } } How do I access the properties of myMovieClip. root.* gives me an error. Another question; If one class creates the object dynamically in actionscript, can I have a different class edit the properties of that class
Uploading then displaying photo on stage.   (121 Views)
I found a file that lets me upload a file and display it but it's in AS2 not 3, plus this tutorial uses a scrollPane to output the upload to... Is there an easier method for doing this , or could I just convert this to AS3 heres the tutorial link http://www.flash-db.com/Tutorials/upload/ Flash-DB Upload Tutorial
Sprite trying to remove itself from the stage is throwing errors.   (168 Views)
I'm trying to have a bullet Sprite remove itself from the stage once it is off the stage, but Flash keeps throwing #1009 errors at me. I've looked over the code several times and don't understand what's wrong. Bullet code: Code: package { import flash.display.Sprite; import flash.display.MovieClip; import flash.events.*; public class Bullet extends Sprite { private var bullet_direction; private var bullet_speed; public function Bullet(xLoc:Number, yLoc:Number, angle:Number, speed:Number) { x = xLoc; y = yLoc; bullet_direction = angle; bullet_speed = speed; addEventListener(Event.ENTER_FRAME, BulletMovement,false,0,true); } public function BulletMovement(e:Event) { y -= bullet_speed * Math.sin(bullet_direction); x += bullet_speed * Math.cos(bullet_direction); if ( x > 500 || x < -20 || y > 660 || y < -20 ) { DestroyBullet(); } } public function DestroyBullet():void { removeEventListener(Event.ENTER_FRAME, BulletMovement); (stage as MovieClip).removeChild(this); } } } Error message: Code: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Bullet/DestroyBullet() at Bullet/BulletMovement()
AS3: Cropping externally loaded SWF to stage bounds   (147 Views)
Hi folks, this is more of a "preemptive strike" question than any real sense of emergency, but I have been unable to find any discussion on the topic anywhere so I thought I'd throw it out here. When using the Loader class to load an external SWF into another timeline and then displaying that SWF using addChild on the loader.content, one discovers to one's consternation that elements positioned off the stage of the external SWF are still displayed. To illustrate this with an example: suppose you have a 500x500 pixel "main" SWF, and it loads an external SWF at runtime and positions it in the center of the stage. And suppose that this external SWF's document properties set the stage width to 200 x 200 pixels. However, when authoring this external SWF, we draw a box that's 300 x 300 pixels, so part of this box is actually off-stage. When you play the external SWF in the standalone Flash player, it is sized correctly at 200 x 200 pixels, and the rest of this box is cropped off. When you load this external SWF into the "main" SWF and use addChild() to put it on the stage, you will see the full 300 x 300 pixel box. -------------- Now of course, we can simply solve the issue using a mask, but I'm wondering whether there's a more elegant solution that's built in, either to the MovieClip or the Loader or the LoaderInfo classes. Something that says "respect the document bounds of the original SWF" or "crop to stage dimensions". Anyone come up with an AS-only solution that does not require re-authoring the external SWF
Detecting keyboard presses on the stage from an external class?   (105 Views)
! I am working on a small section of my game and am attempting to detect key presses from an external class but I cannot get it to work. This code worked just fine when within the document class but now it's unresponsive. I'm not getting any errors, simply no activity whatsoever. Here's the applicable code: My document class: Code: package { import flash.display.MovieClip; public class Engine extends MovieClip { public var itemTest:ItemTest; public function Engine() { itemTest = new ItemTest(this); } } } My external class: Code: public function Abilities(ref:*) { stageRef = ref; Keys(); } public function Keys() { stageRef.addEventListener(KeyboardEvent.KEY_DOWN, checkKeys, false, 0, true); } public function checkKeys(keyboardEvent:KeyboardEvent) { if ( keyboardEvent.keyCode == 83 ) // The "s" key. downPressed(); trace("down!"); if ( keyboardEvent.keyCode == 87 ) // The "w" key. upPressed(); trace("up!"); } I'm pretty sure it has to do with my stage reference but I have no idea how to go about making it functional again. Any ideas
navagiting or accessing objects added to stage   (114 Views)
I have a structure display like this: (brackets shows the depths, within their parent) my question concerns 'communication' between the highlighted objects - so you don't have to waste time understanding the whole tree! I've just added this to provide some context! mc_init (0) ___| ___mc_page (0) ______| ______rectangleBG (0) ______| ______textTitle (1) __ | ___mc_setup (1) ______| ______mc_setupBG (0) ____________| ____________mc_site (0) ____________| ____________mc_pref (1) ____________| ____________mc_edit (2) ________________| ________________text (0) ________________| ________________btn (1) Now, its easy to add a mouse event to btn(1), but how do I get this button to set the visible property (say) of 'rectangleBG(0)' So my question is how do I access the paths of these objects added to the stage any help on this would help my headache to go away! Ikonik
access class from stage MC   (180 Views)
..
resizing the stage ?   (105 Views)
How can I resize the stage according to the number of cells I add to a table in my project
Clear stage   (106 Views)
Hi I'm using AS 3.0 to generate movieClips to display external data from XML in Flash. These data need to update every xxx seconds. But at reloading it just writes the new data on top of the old data... Since not every update will have the same number of lines or clips next to eachother I need to clear the whole stage at once before writing the new data. Can someone tell me how to clear the whole stage at once Thanx in advance. Lucky
Creating a box/field/area on stage to place horizontal scrolling image gallery into   (126 Views)
all! I've created an XML driven horizontal image gallery which scrolls to the left when you hover the mouse over the left side and to the right when you hover over the right side. The gallery consists of 7 thumbnails which makes the row of images quite long. When placed on the stage it stretches out all over the stage. I want the gallery to be in a certain area or field on the stage which has room for about 3 of the 7 thumbs and then use the scrolling feature to scroll through the thumbs and see them all. How can I achieve this Is it possible to create an invisible field or box to put the gallery in or something Do I have to fix this in via the XML file I have set the width of the gallery in the XML file, but if I set it too low the thumbs are all squized together. I'm hoping someone can give me some advice on this.
stage text field access from class   (151 Views)
, A simple access from class question: I have a dynamic text field on my stage, instance name: "lives_txt" I want to populate this field from my Document class "Ball.as" So in my Ball.as class I have tried: parent.lives_txt.text = String (lives); where: public var lives:int = 3; I get an error: access of possibily undefined property lives_mc through a reference with static type flash.displayisplayObjectContainer. What am I doing wrong
wtflizap add to stage already!   (137 Views)
Flash CS3 finally upgraded. WOW! Figured it out had to pass the stage through. JC!!!!!!!! wTf
About "Automatically declare stage instances"   (143 Views)
Automatically declare stage instances... do you design with that box checked or unchecked If I uncheck it, in order to avoid conflict when I create external classes, how can I easily refer to the children of my instance For example, I have myClass.myBackground. I would like to access to myBackground (but if the box is unchecked I can't...)
reflection/mirror with XML(not with on stage MC's)   (112 Views)
Halo! [Summary] using the Adobe's Reflect class (reflect_class_as3.zip (ZIP, 4K))to add reflections to dynamically loaded images (loaded using the xml loader class). Reflections tested with on-stage movieclips work, but, gives error (Error #1034: conversion impossible flash.display::Loader to flash.display::MoveClip) when applied to XML loaded images. imageLoader = new Loader(); imageLoader.load(new URLRequest(url)); imageLoader.name = "img"; imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); function imageLoaded(e:Event):void { // Add image to container //trace(MethodInfo-353()); visionneuse.vis_img.addChild(imageLoader); visionneuse.vis_img.removeChildAt(0); // reflect the images var r1 = new Reflect({mc:imageLoader, alpha:100, ratio:255, distance:0, updateTime:-1, reflectionDropoff:4}); } [SYMPTOMS] This happens only when the images are loaded using the XML loader class. [MORE INFORMATION] I tried to find reflection classes that support xml but in vain. Posted also a comment on the classe's page but with no answer. thanx for any help.
No compiler errors...nothing on stage!   (165 Views)
well i have this code as compiled class Code: package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; public class Bouncing extends Sprite { private var ball:Ball; private var vx:Number; private var vy:Number; public function Bouncing(); { init(); } private function init():void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; ball = new Ball(); ball.x = stage.stageWidth / 2; ball.y = stage.stageHeight / 2; vx = Math.random() * 10 - 5; vy = Math.random() * 10 - 5; addChild(ball); } } } and this sub-class Code: package { import flash.display.Sprite; public class Ball extends Sprite { public var radius:Number; private var color:uint; public function Ball(radius:Number = 20, color:uint = 0xFF0000) { this.radius = radius; this.color = color; init(); } public function init():void { graphics.beginFill(color); graphics.drawCircle(0, 0, radius); graphics.endFill(); } } } I get no complier errors , but the swf is empty(background color 0x000000). Can' t find the error which drives me crazy! Anyone experienced similar situation (always wanted to use yoda!)
Removing/Destroying Movieclips outside stage   (101 Views)
The objective is to destroy dynamic movieclips that exit the stage. I have the following code (loop through array of bullets to see if any have exited the stage) in timeline (looping each frame, in gameLoop): Code: var bLength = myBulletArray.length; for (var i:int = 0; i stage.stageHeight || myBulletArray[i].y < 0 || myBulletArray[i].x > stage.stageWidth || myBulletArray[i].x < 0) { removeChild(myBulletArray[i]); myBulletArray[i] = null; myBulletArray.splice(i,1); } } This causes an error (not fatal), when there is more than one movieclip at the stage at the sametime and first of the bullets has been removed: Code: TypeError: Error #1010: A term is undefined and has no properties. at Game_fla::MainTimeline/gameLoop() (But when you shoot just one bullet at a time (and wait for it to destroy before launching new one), it works without errors.. ) Anyone has stumbled into this before If so, need some help to figure this out! EDIT: Nevermind, solved it by checking the arrays length in every loop, not just before the looping: Code: for (var i:int = 0; i
Problem using "stage" from class   (84 Views)
I quess my problem is pretty common (hope so), but unfortunately haven't found any solutions to it so far . I want to have a "mouse down" listener in "Player" class file, which listens if player clicks the stage. So, i have actionscript file "Player" and there i have following code: Code: public function Player() { this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true); stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); } But when i start the game, error says: Code: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Player$iinit() at Game_fla::MainTimeline/Game_fla::frame1() I know the problem is with "stage". I quess the game hasn't loaded the Stage class before i am using it in "Player" class, and that causes problems Anyone know solution for this one Or is the only solution to write all the code, that has anything to do with stage to timeline frame. Oh yeah, and i'm using Flash CS3.