Hey everyone,
I'm trying to import an external SWF with a scrollbar, calling out to an external .AS, into my main SWF. Someone told me, it's an issue that my scrollbar isn't instantiated yet, but stopped short of helping me how to fix the problem.
Here's the error below:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Scrollbar/init()
at Sample2_fla::MainTimeline/scInit()
at flash.display::DisplayObjectContainer/addChild()
at Sample2_fla::MainTimeline/frame1()
On my main SWF, I was to click a button and load my external SWF. I want to then click another button in the external SWF and reveal my scrollbar (alpha=1;). The scrollbar is the issue.
Here's my script:
Sample1.swf (main)
this.addEventListener(MouseEvent.CLICK, clickListener);
var oldSection=null;
function clickListener(evt:Event) {
if (evt.target.name=="button_btn") {
loadSection("Sample2.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);
}
function sectionLoadedListener(evt:Event) {
var section=evt.target.content;
if (oldSection) {
removeChild(oldSection);
}
oldSection=section;
addChild(section);
section.x=0;
section.y=0;
}
Sample2.SWF (external):
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
scroll_mc.alpha=0;
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();
}
button2_btn.addEventListener(MouseEvent.CLICK, clickListener);
function clickListener(evt:MouseEvent){
TweenMax.to(this.scroll_mc, 1,{alpha:1});
}
I really appreciate your help.
Cheers!