I'm building a small Flash Projector file. I'm loading external SWFs into a main SWF. The external SWFs will contain a scrollbar (sometimes 2) imported from a folder. The scrollbar works fine in the external SWF, but when I try to all the SWF to the main SWF, I get the following error. I'm still a novice to AS3.
[object maschera_8] TypeError: Error #1009: Cannot access a property or method of a null object reference. at Scrollbar/init() at loaded_fla::MainTimeline/scInit() at flash.display::DisplayObjectContainer/addChild() at loaded_fla::MainTimeline/frame1()
Here's the source code for the Main SWF, followed by the source code for the external SWF:
//clickListener for oldSection =================================================================
this.addEventListener(MouseEvent.CLICK, clickListener0);
var oldSection = null;
// clickListener for the Products buttons ======================================================
function clickListener0(evt:Event) {
// test for nav links -----------------------------
if (evt.target.name == "blue_btn") {
loadSection("loaded.swf");
} else if (evt.target.name == "red_btn") {
loadSection("red.swf");
}
function loadSection(filePath:String) {
var url:URLRequest = new URLRequest(filePath);
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, sectionLoadedListener);
ldr.load(url);
}
}
// sectionLoadedListener =======================================================================
function sectionLoadedListener(evt:Event) {
var section = evt.target.content;
if (oldSection) {
this.removeChild(oldSection);
}
oldSection = section;
this.addChild(section);
//section.alpha=0;
section.x=0;
section.y=0;
//TweenLite.to(section,0.5,{x:-537.9, y:-189.5, alpha:1, ease:Quart.easeInOut});
}
External SWF source code:
import Scrollbar;
var sc:Scrollbar=new Scrollbar(scroll_mc.text,scroll_mc.maskmc,scroll_mc.scrollbar.ruler,scroll_mc.scrollbar.background,scroll_mc.area,true,6);
sc.addEventListener(Event.ADDED, scInit);
addChild(sc);
function scInit(e:Event):void {
sc.init();
}