错误#1009无法访问空对象引用的属性或方法

时间:2010-04-05 19:49:14

标签: actionscript-3 flash

我正在尝试使用滚动条导入外部SWF,将外部.AS调用到我的主SWF中。有人告诉我,这是一个问题,我的滚动条尚未实例化,但没有帮助我如何解决问题。

以下是错误:

  

TypeError:错误#1009:无法访问null的属性或方法   对象参考。在Scrollbar / init()处   Sample2_fla :: MainTimeline / scInit()at   flash.display :: DisplayObjectContainer / addChild()at   Sample2_fla :: MainTimeline /帧1()

在我的主SWF上,我点击一个按钮并加载我的外部SWF。我想然后单击外部SWF中的另一个按钮并显示我的滚动条(alpha = 1;)。滚动条是个问题。

这是我的剧本:

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(外部):

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});
    }

我非常感谢你的帮助。

干杯!

1 个答案:

答案 0 :(得分:0)

您正在使用var sc:Scrollbar。我想你希望它成为班级的财产。 scInit无权访问sc,它为null。

相关问题