Hello, this is my first post , so please excuse me if there are some mistakes.
I’m new to AS3. From few days i work on a project of animated banner with dynamic text. Everything worked perfect until I’ve moved the some text areas from the main scene to an movie clip. Now the text animates ok, and also the banner work fine( if you wait for 2/3 loops), but I always get this errors in to output window:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at layout_animated_fla::MainTimeline/onLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at layout_animated_fla::MainTimeline/cssLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
The AS3 code for this is:
//Load text from external file
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void
{
title_txt.htmlText = e.target.data.titleText1;
body_mc.body_txt1_mc.body_txt1.htmlText = e.target.data.bodyText1;
body_mc.body_txt2_mc.body_txt2.htmlText = e.target.data.bodyText2;
price_txt.htmlText = e.target.data.priceText;
footer_txt.htmlText = e.target.data.footerText;
order_txt.htmlText = e.target.data.orderText;
play_txt.htmlText = e.target.data.playText;
}
myTextLoader.load(new URLRequest("myText.txt"));
//Load CSS styles from external file
var cssReq:URLRequest = new URLRequest("style.css");
var cssLoader:URLLoader = new URLLoader();
function cssLoaded(event:Event):void
{
var sheet:StyleSheet = new StyleSheet();
sheet.parseCSS(cssLoader.data);
title_txt.styleSheet = sheet;
body_mc.body_txt1_mc.body_txt1.styleSheet = sheet;
body_mc.body_txt2_mc.body_txt2.styleSheet = sheet;
price_txt.styleSheet = sheet;
footer_txt.styleSheet = sheet;
order_txt.styleSheet = sheet;
play_txt.styleSheet = sheet;
}
cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
cssLoader.load(cssReq);
The problem is only with the body_mc.body_txt1_mc.body_txt1.htmlText = e.target.data.bodyText1; and body_mc.body_txt2_mc.body_txt2.htmlText = e.target.data.bodyText2; and their css Code. If i comment this lines everything works with no error.
What i think it maybe a problem is that the instance is not loaded on stage when I execute the onLoaded function.