DataProvider' article example works but issues TypeError: Error #1009 at the same time - actionscript-3

Reading up on DataProvider here
The second code example that displays the data of a selected item, from the list, inside the TextArea.
The article's code, while does what it suppose to do, gives me the following error:
TypeError: Error #1009: Cannot access a property or method of a null
object reference. at fl.controls::TextArea/drawLayout() at
fl.controls::TextArea/draw() at
fl.core::UIComponent/callLaterDispatcher()
Why is that?

Turns out I had to also have the TextArea control inside my library.

Related

How to fix an error #1009 in a class added to Main?

I have a class called ChestScene that represents a scene/MovieClip in a .fla file I'm working on. I've had tons of issues that seem to be rooted in a fundamental misunderstanding of how to properly use objects that have code attached to them. It is my understanding that adding the object to the stage automatically instantiates it, so right now all I'm trying to do is instantiate and add to stage ChestScene() in the constructor of my Main method. I thought it would be as simple as this:
public class Main extends MovieClip {
var chest:Chest = new Chest();
public function Main() {
stage.addChild(chest);
}
But I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Chest()/startScene()
at Chest()
at Main()
So my first question is why is Chest null? The object exists in my fla. If I add it to the stage by dragging from the library, the class works as intended. addChild seems to work on other objects that I am using the same way so I don't get why I can't use it on this object.
How to use the Main method to instantiate an object and access/change properties of said object relative to the stage? And how can I do the same thing for the objects nested inside of my initial object?
***** Edit after answer
Thanks for your reply and for teaching me how to read the debug message. startScreen() was indeed the culprit, and the issue there was this:
stage.addEventListener(Event.ENTER_FRAME, gameLoop)
Removing stage and adding the listener to the object fixed that error, so kudos! But I'm still confused; why does trying to add the listener to the stage cause a null error? I don't understand why the stage would be null at this point. Also, removing "stag." from the addEventListener caused the size of the frame that holds the scene to be way smaller, which cropped a lot of my image. Why is an event listener affecting my stageWidth and height? This is why I also asked questions about how to correctly position things relative to the stage width and height, because I know it has something to do with the errors.
why is Chest null?
Chest is not null. It's the constructor of the class and cannot be null.
You should pay attention to the Stack trace attached to the error (the lines with "at …" below the message).
It tells you where the error occurred. Reading it from the bottom up gives you the order of method calls performed.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Chest()/startScene()
at Chest()
at Main()
Main() called Chest(), Chest() called startScene() and BOOM! this is where the error occurred.
To debug this error look at startScene() . Something in there is null.
Looking at your current code:
stage.addChild(chest);
I guess that you also try to add something to stage in Chest(). But stage is not available ( null) in Chest().
In general, it's bad practice to add things to stage as can be read in the documentation of addChild()
Simply add to the object and not stage :
addChild(chest);

Getting error while maintaining flash code

I am new to flashbuilder. I have got this existing code to maintain. All of the mxml files have outermost tag s:WindowedApplication. The navigation from one page to another is done using code as follows:
public function help_clickHandler(event:MouseEvent):void
{
var dTracker:aboutProduct = new aboutProduct();
this.addElement(dTracker);
}
After navigating to a new page I get following error on clicking any where on newly loaded page:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/getChildIndex()
at mx.managers::SystemManager/getChildIndex() [E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:1823]
at mx.managers.systemClasses::ActiveWindowManager/mouseDownHandler() [E:\dev\4.y\frameworks\projects\framework\src\mx\managers\systemClasses\ActiveWindowManager.as:483]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at mx.managers::SystemManager/mouseEventHandler() [E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2918]
Error: Error #3003: File or directory does not exist.
at flash.filesystem::File/copyTo()
at studyTopics/studytopic_changeHandler()[C:\flash\46\HondaLMS\src\studyTopics.mxml:81]
at studyTopics/__lst_change()[C:\flash\46\HondaLMS\src\studyTopics.mxml:136]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at spark.components::List/commitSelection()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\List.as:1278]
at spark.components::List/commitProperties()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\List.as:1148]
at mx.core::UIComponent/validateProperties()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:8219]
at spark.components::List/item_mouseDownHandler()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\List.as:1915]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at mx.managers::SystemManager/mouseEventHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2918]
Please help me solve this runtime error.
Update:
There is a technical error in the design of application, i.e., all of the mxml have WindowApplication. There should be only one WindowApplication and rest of them should be Application type (reference). Still I have to figure out, how to navigate from one page to another page and return back to main page or previous page.
In one flex application there can be only one mxml with WindowApplication container. Rest of the containers should be Group.
I left landing page as WindowApplication and changed rest in Group, this revolved the issue I was facing.

TypeError: Error #1009: Cannot access a property or method of a null object reference. When trying to create a button.

Heyy, Im having some problems with my buttons. What I have is 4 buttons on the page. They will run an animation while not being pressed, and that animation will change when it is being pressed.
I keep getting the error TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MultimediaAssignment_fla::MainTimeline/frame51()[MultimediaAssignment_fla.MainTimeline::frame51:3]
And I have searched high and low but I cant seem to find anyone who is having the same problem as me.
stop();
btn_volcano.addEventListener(MouseEvent.CLICK, volcano);
btn_Storm.addEventListener(MouseEvent.CLICK, stormbtn);
btn_Tsunami.addEventListener(MouseEvent.CLICK, tsunamibtn);
btn_Earthquake.addEventListener(MouseEvent.CLICK, earthquakebtn);
function volcano(e:MouseEvent):void {
gotoAndPlay(52);
}
function tsunamibtn(e:MouseEvent):void {
gotoAndPlay(54);
}
function stormbtn(e:MouseEvent):void {
gotoAndPlay(53);
}
function earthquakebtn(e:MouseEvent):void {
gotoAndPlay(55);
}
My buttons do have correct instance names and for some reason it worked when I turned the "up" movie clip into a button and called it e.g. btn_volcano. Except if I do that the animation doesn't run anymore.
If I remove the instance name from in front of the event listener I don't get the error but it will only ever run the last code.
Please help!
error TypeError: Error #1009: Cannot access a property or method of a null object reference. at MultimediaAssignment_fla::MainTimeline/frame51()
This line suggests you have some code in frame 51. I presume in Flash IDE in main timeline.
Click on this frame on timeline and open actions window. Problem may be there.

Error #1009: Cannot access a property or method of a null object reference

This is quite frustrating. I am simply trying to create a dynamic text and put some text into it on runtime.
I get this error though
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I have a text object named textLabel, which is inside a movieclip named MC_state.
I get it because I use:
MC_state.textLabel.text = "asdasd";
And I wish I knew what the problem was. I have other objects set up quite the same way which don't give me that problem. I just don't know how debug that.
Thanks!
The error is telling you that there is no object somewhere along MC_state.textLabel.text, so either flash cannot find MC_state, or textLabelinside MC_state or (unlikely) text inside MC_state.textLabel.
If I may venture a guess though, I think you're seeing this because this happened:
you have somewhere a movieclip called MC_state that has more than one frames. You tied to do gotoAndStop or gotoAndPlay to a frame that has the textfield called textLabel and that's the text you're trying to change.
The problem, and it comes up often for people transitioning from AS2, is that when you execute the gotoAndPlay/gotoAndStop function, the movieClip doesn't update right away, this happens iin the render phase. The code after that function however executes right away, so the movieclip is still at the old frame.
there are two ways you can handle it
set up a event handler that updates the render event, and change the text then. You can hurry the stage rendering by running stage.invalidate example
the other (better) option is to have the text in all the frames, and have it hidden or invisible, that way you can access it at any time.

Error 1009 in AS3

I have TextField instance called inputWord which contains no text on the first frame. On the same frame, on the actions layer, any time when I refer to inputWord in any way, there is an error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DC/frame1()[DC::frame1:19] //DC is the name of document class that I created.
at flash.display::MovieClip/gotoAndStop()
at DC()[C:\Users\nikkka\Desktop\flash\DC.as:25]
19 is the number of line where my code that involves inputWord is located. It works, I mean I write
inputWord.text = "smth"
it text becomes "smth" but there is the same error. Why?
The problem is with gotoAndStop()
in as2, when you do a gotoAndStop you can access the resources in the frame right away, as Kevin pointed out, the frame has to be rendered first
to do this, you need to use an onrender listener to fire when you rendered the frame to deal with the frame related logic. Then you need to invalidate the stage, to force the rendering to fire.
like so:
stage.addEventListener(Event.RENDER, onRenderStage);
protected function onRenderStage(ev:Event):void {
inputWord.text = "smth"
trace(inputWord.text);
}
gotoAndStop(5);
stage.invalidate();
Probably on the first frame, inputWord is not loaded yet so you get an error. On the next frames, it is loaded so the text is being set successfully. The solution is test for the existence of the text field before setting it:
if (this.inputWord) this.inputWord.text = "smth";