Search code examples
flashactionscript-3

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

Solution

  • 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