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 findMC_state, ortextLabelinsideMC_stateor (unlikely)textinsideMC_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_statethat has more than one frames. You tied to do gotoAndStop or gotoAndPlay to a frame that has the textfield calledtextLabeland 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.invalidateexamplethe 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.