TypeError: Error #1009: Cannot access a property or method of a null object reference.
at QuizApp/createButtons()
at QuizApp()
My QuizApp is an Actionscript file that runs with another for my quiz.
The createButtons() is accessed like this
package{
public class QuizApp extends Sprite {
public function QuizApp() {
createQuestions();
It runs by itself fine but when i attatch it to play off a button i get this error, i would really appreciate some advice on how to go about figuring this out.
Thanks
My QuizApp is an Actionscript file with some of the below and its loaded as a document class into a blank 3.0 flash file called Quiz.fla with the buttons in the library. The only problem is, this error occures when i load the Quiz.fla from a button on another timeline, otherwise it works fine.
Code:
package {
import flash.display.Sprite;
import fl.controls.Button;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class QuizApp extends Sprite {
//for managing questions:
private var quizQuestions:Array;
private var currentQuestion:QuizQuestion;
private var currentIndex:int = 0;
//the buttons:
private var nextButton:Button;
private var finishButton:Button;
//scoring and messages:
private var score:int = 0;
private var status:TextField;
public function QuizApp() {
quizQuestions = new Array();
createQuestions();
createButtons();
createStatusBox();
addAllQuestions();
hideAllQuestions();
firstQuestion();
}
I have my questions then the button appear from this:
yes another FLA. My timelines, i have a main menu.fla which has a button that loads the intro.fla, that is frame based cuz when its finished (on frame w.e) it loads the Quiz.fla im just not sure where to insert your line
um, the intro.fla which calls the Quiz.fla to play when finished has custom buttons but the Quiz.fla library only has a button and a radio button which were pulled out of the common library for use by its document class QuizApp which is an actionscript file. The Quiz.fla also has another actionscript file attached to it call QuizQuestions. Im not sure if that helps at all.
but thanks so much for the reply, i really appreciate it.
I dont know what you mean by zip them up and post them though.
I'm pretty sure it is because CreateButtons can't find the stage instance. I've had trouble with this in the past. This would affect the first line of the function.
I ususally get round this by manually adding a sprite to the stage in the main fla file. Have it match the stage dimensions and be accessible by action script. Give it a variable name in the IDE, eg myStage.
If this is all running in your document class, the function should work if you change all the references of 'stage' to 'myStage'. If it's not in the document class you will have to pass a reference to myStage into the constructor of your other classes.
I hope this helps.
P.S. This is actually a good practice to get into as if you are ever wrapping your swf in another, eg for widget sharing or something, you may find that calls to stage are blocked by the containing movie.
Last edited by peter.hastie; 04-16-2009 at 05:11 PM.
Reason: Thought of more stuff (P.S.)
Ah i c, i get what your doing. Um would you be able to give me a quick crash course on how to add sprite to stage for us unexperienced guys out there
thanks for the reply very much
Sorry I haven't posted up an example of what I was talking about yet. I shall try to do that today or tomorrow. In the meantime though, have you tried moving the call to stage to after the line where the button is added to the stage?
Hi peter
What do you mean by moving the call to stage to after the line where the button is added to the stage?
Im not exactly sure what you mean by this because my buttons and my code for the QuizApp.swf are on different files, do you mean calling to this swf from the timeline that has the button instead of after?