开发者

Error #1009: in flash project

I am getting this error-

TypeError: Error #1009: Cannot access a property or method of a null object reference. at final_fla::MainTimeline/frame2()

Most of my project wo开发者_StackOverflow社区rks perfectly still - but the one part that loads photos doesnt do anything when the button is pressed. My code -

import fl.transitions.Tween;
import fl.transitions.easing.*;

stop();

function goHome (e:MouseEvent):void{
gotoAndStop("Home");
}
home_btn.addEventListener(MouseEvent.CLICK, goHome);

function goAbout (e:MouseEvent):void{
gotoAndStop("About");
}
about_btn.addEventListener(MouseEvent.CLICK, goAbout);

function goWhat (e:MouseEvent):void{
gotoAndStop("What");
}
what_btn.addEventListener(MouseEvent.CLICK, goWhat);

function goHow (e:MouseEvent):void{
gotoAndStop("How");
}
how_btn.addEventListener(MouseEvent.CLICK, goHow);

function goPricing (e:MouseEvent):void{
gotoAndStop("Pricing");
}
price_btn.addEventListener(MouseEvent.CLICK, goPricing);

function goContact (e:MouseEvent):void{
gotoAndStop("Contact");
}
contact_btn.addEventListener(MouseEvent.CLICK, goContact);



play_btn.addEventListener(MouseEvent.CLICK, goPlay)

var images = new Array();

images[0] = "1.png";
images[1] = "2.png";
images[2] = "3.png";
images[3] = "4.png";
images[4] = "5.png";

var currentImage:int = 0;
var myTimer:Timer = new Timer(5000, 0); // 5 seconds
myTimer.addEventListener(TimerEvent.TIMER, switchPics);

function goPlay(e:MouseEvent) {
   myTimer.start();
}

function switchPics(event:TimerEvent):void {
   currentImage = (currentImage+1)%images.length;
   loadWindow.source = images[currentImage];
   var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 5, true);
}


UPDATED

var images : Array = new Array();
    images.push("1.png");
    images.push("2.png");
    images.push("3.png");
    images.push("4.png");
    images.push("5.png");

Are you sure that the UILoader exists on the frame you are starting the script from? I tested everything but the buttons and it works fine. I think that the UILoader (loadWindow) does not exist on the frame you are currently at when you trigger the function switchPics.


Everything looks fine if loadWindow exists.

My guess:

  • loadWindow is not declared
  • loadwindow is not created
  • loadwindow does not accept source parameter/setter


Looks like you are missing a semi-colon at:

play_btn.addEventListener(MouseEvent.CLICK, goPlay)

Right before line 40 where you are getting the error


Sometimes object hasn't been loaded yet. This can be solved with:

this.addEventListener(Event.ENTER_FRAME,checkLoaded)
function checkLoaded(e:Event){
    if(mc){
        //something
        this.removeEventListener(Event.ENTER_FRAME,checkLoaded)
    }
}

Sometimes the eventlisteners should be removed to solve this problem

UPDATE

I test the code and I think that Mattias is right. Look to the frames where you put the UILOADER with instance name loadWindow and try to put then in all frames of your project to test

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜