[英]AS3 - Error #1009: Cannot access a property or method of a null object reference
[英]Error #1009 Cannot access a property or method of a null object reference
我正在尝试使用滚动条导入外部SWF,并调用外部.AS到我的主SWF中。 有人告诉我,这是一个问题,我的滚动条尚未实例化,但是没有帮助我解决问题。
这是以下错误:
TypeError:错误#1009:无法访问空对象引用的属性或方法。 在滚动条/ 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});
}
非常感谢您的帮助。
干杯!
您正在使用var sc:Scrollbar。 我认为您希望将其作为班级的财产。 scInit无权访问sc,它为null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.