Could anyone help me with setting the UILoader's source?

Hi,

I’m trying to write a simple AS class that let’s me click a button (instance name is fader) on frame 1, which will take me to frame 2 where a UILoader component will load an external image. Eventually, I want to have several buttons that set a different source for the UILoader component (instance name is img). This is my code so far below:

package {
    

    import flash.display.MovieClip
    import flash.display.Shape
    import flash.display.SimpleButton
    import flash.events.MouseEvent
    import fl.containers.UILoader
    
    public class HelloWorld extends MovieClip {
        public function HelloWorld () {
            
            fader.addEventListener(MouseEvent.MOUSE_DOWN,transition);
            function transition(e:MouseEvent) {
                gotoAndPlay(2);
                img.source = "1.jpg";
            }
            
            
        }
        
    }
    
}

But whenever I compile I get this error…

TypeError: Error #1009: Cannot access a property or method of a null object reference. at MethodInfo-221()

Could anyone please help? :slight_smile: