【发布时间】:2010-04-05 19:49:13
【问题描述】:
我正在尝试将带有滚动条的外部 SWF(调用外部 .AS)导入到我的主 SWF 中。有人告诉我,这是我的滚动条尚未实例化的问题,但没有帮助我解决问题。
以下是错误:
TypeError:错误 #1009:无法访问 null 的属性或方法 对象引用。在滚动条/init() 处 Sample2_fla::MainTimeline/scInit() 在 flash.display::DisplayObjectContainer/addChild() 在 Sample2_fla::MainTimeline/frame1()
在我的主 SWF 上,我要单击一个按钮并加载我的外部 SWF。然后我想单击外部 SWF 中的另一个按钮并显示我的滚动条 (alpha=1;)。滚动条是问题所在。
这是我的脚本:
Sample1.swf(主要)
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(外部):
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});
}
非常感谢您的帮助。
干杯!
【问题讨论】:
标签: actionscript-3 flash