Hello, I need help cause I’m not sure how to fix this error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Final_fla::MainTimeline/frame1()
I’m not sure where the error is so I’ll paste my code. The first code I have on frame 1 and the second I have on frame 2.
On frame one:
stop()
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
one.addEventListener(MouseEvent.CLICK, oneButtonClick);
two.addEventListener(MouseEvent.CLICK, twoButtonClick);
three.addEventListener(MouseEvent.CLICK, threeButtonClick);
function oneButtonClick(e:MouseEvent):void
{
gotoAndStop(1);
}
function twoButtonClick(e:MouseEvent):void
{
if(myEmptyContainer != null){
myEmptyContainer.removeChild(imageLoader3);
imageLoader3 = null;
stage.removeChild(myEmptyContainer);
myEmptyContainer = null;
}
gotoAndStop(2);
}
function threeButtonClick(e:MouseEvent):void
{
if(myEmptyContainer != null){
myEmptyContainer.removeChild(imageLoader3);
imageLoader3 = null;
stage.removeChild(myEmptyContainer);
myEmptyContainer = null;
gotoAndStop(1);
}
}
// The code below will create a StyleSheet instance and apply that
// to any instance on the stage you specify, in this example
// it is applied to a text field instance named my_text_field
function cssLoadComplete(event:Event):void
{
styles.parseCSS(cssLoader.data);
// Now assign the StyleSheet to a text field for example
my_text_field.styleSheet = styles;
}
var cssLoader:URLLoader = new URLLoader();
var cssRequest:URLRequest = new URLRequest("style.css");
var styles:StyleSheet = new StyleSheet();
cssLoader.load(cssRequest);
cssLoader.addEventListener(Event.COMPLETE, cssLoadComplete);
function textLoadComplete(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field.htmlText = textLoader.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader.data);
}
var textLoader:URLLoader = new URLLoader();
var textReq:URLRequest = new URLRequest("para.txt");
textLoader.load(textReq);
textLoader.addEventListener(Event.COMPLETE, textLoadComplete);
function textLoadComplete2(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field_two.htmlText = textLoader2.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader2.data);
}
var textLoader2:URLLoader = new URLLoader();
var textReq2:URLRequest = new URLRequest("para_two.txt");
textLoader2.load(textReq2);
textLoader2.addEventListener(Event.COMPLETE, textLoadComplete2);
function textLoadComplete3(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field_three.htmlText = textLoader3.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader3.data);
}
var textLoader3:URLLoader = new URLLoader();
var textReq3:URLRequest = new URLRequest("para_three.txt");
// you need to set your TextFormat instance as the default
// format for your text field. This must be done before you
// add any text to your text field.
var myFormat:TextFormat = new TextFormat();
textLoader3.load(textReq3);
textLoader3.addEventListener(Event.COMPLETE, textLoadComplete3);
function textLoadComplete4(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field_four.htmlText = textLoader4.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader4.data);
}
var textLoader4:URLLoader = new URLLoader();
var textReq4:URLRequest = new URLRequest("para_four.txt");
textLoader4.load(textReq4);
textLoader4.addEventListener(Event.COMPLETE, textLoadComplete4);
// Use URLRequest to link to the external image file
var extImage:URLRequest = new URLRequest("sketch.jpg");
// Use Loader to load the external image file
var imageLoader:Loader = new Loader();
imageLoader.load(extImage);
addChild(imageLoader);
imageLoader.x=410;
imageLoader.y=255;
On Frame 2
stop()
function textLoadComplete5(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field.htmlText = textLoader5.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader5.data);
}
var textLoader5:URLLoader = new URLLoader();
var textReq5:URLRequest = new URLRequest("para.txt");
textLoader5.load(textReq5);
textLoader5.addEventListener(Event.COMPLETE, textLoadComplete5);
function textLoadComplete6(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field_six.htmlText = textLoader6.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader5.data);
}
var textLoader6:URLLoader = new URLLoader();
var textReq6:URLRequest = new URLRequest("para_six.txt");
textLoader6.load(textReq6);
textLoader6.addEventListener(Event.COMPLETE, textLoadComplete6);
function textLoadComplete7(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field_seven.htmlText = textLoader7.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader5.data);
}
var textLoader7:URLLoader = new URLLoader();
var textReq7:URLRequest = new URLRequest("para_seven.txt");
textLoader7.load(textReq7);
textLoader7.addEventListener(Event.COMPLETE, textLoadComplete7);
function textLoadComplete8(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field_eight.htmlText = textLoader8.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader5.data);
}
var textLoader8:URLLoader = new URLLoader();
var textReq8:URLRequest = new URLRequest("para_eight.txt");
textLoader8.load(textReq8);
textLoader8.addEventListener(Event.COMPLETE, textLoadComplete8);
function textLoadComplete9(event:Event):void
{
// Some code to do something with the loaded text
// For example you have a text field instance called
// my_text_field, so you could do
// my_text_field.text = textLoader.data;
// or for HTML text
my_text_field_nine.htmlText = textLoader9.data;
// make sure data is being received
// remember to remove or comment out trace
//trace(textLoader5.data);
}
var textLoader9:URLLoader = new URLLoader();
var textReq9:URLRequest = new URLRequest("para_nine.txt");
textLoader9.load(textReq9);
textLoader9.addEventListener(Event.COMPLETE, textLoadComplete9);
// Use URLRequest to link to the external image file
var extImage2:URLRequest = new URLRequest("line_color.jpg");
// Use Loader to load the external image file
var imageLoader2:Loader = new Loader();
imageLoader2.load(extImage2);
addChild(imageLoader2);
imageLoader2.x=410;
imageLoader2.y=255;
//Create an empty MovieClip:
var myEmptyContainer:MovieClip = new MovieClip();
stage.addChild(myEmptyContainer);
// Use URLRequest to link to the external image file
var extImage3:URLRequest = new URLRequest("tool_tip.jpg");
// Use Loader to load the external image file
var imageLoader3:Loader = new Loader();
imageLoader3.load(extImage3);
addChild(imageLoader3);
imageLoader3.x=725;
imageLoader3.y=460;
imageLoader3.contentLoaderInfo.addEventListener(Event.INIT, initListener);
function initListener (e:Event):void{
//trace("Object Initialized");
}
imageLoader3.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
function progressListener (e:ProgressEvent):void{
//trace("Loading In Progress");
//trace("Downloaded " + e.bytesLoaded + " out of " + e.bytesTotal + " bytes");
}
imageLoader3.contentLoaderInfo.addEventListener(Event.COMPLETE, startListener);
function startListener (e:Event):void{
myEmptyContainer.addChild(imageLoader3);
//trace("width: " + imageLoader.width + " height: " +imageLoader.height);
//trace("Loading Completed");
}
//add the instance to your empty MovieClip:
myEmptyContainer.addChild(imageLoader3);
Sry if its too long. Thanks to anyone who can help out.
EDIT: for further info, yes, I have all files into one folder. As for why I set my action script like this… I guess the assignment I have was to practice using external files.