Newbie - getting image to load using new Loader () - help

Hi everyone,

I’m new here! I’m a complete newbie using ActionScript for a class I’m taking online (not my choice to have it online, unfortunately). My instructor isn’t much help to me and I am struggling. I am a beginner Flash user so know a little about that program but it’s the AS I’m struggling with.

I’m hoping some experts can help me out because I have spent the last 8 hours trying to get the Loader function to work for me. :frowning: I’m going to attach my code and if someone could PLEASE tell me where the code should go and what I’m doing wrong, I will give you my first born. lol

I am creating a simulation that contains an octopus in a bath tub for the main image. I’m trying to get the octopus to load on my stage using the code my instructor has given me:

var somePictLdr:Loader = new Loader();
var request:URLRequest = new URLRequest(“octopus.jpg”); [COLOR=green]<–this is the name of the jpg I have. I’m on a Mac and the entire folder with all of my stuff is on my desktop named ‘bath2’. Inside this folder, you will find my image.[/COLOR]
somePictLdr.load(request);
addChild(somePictLdr);

He told me this should be a new function so that your old code is not affected. ie use public function after the “bath2” function. I added another function but all I get is a blank screen.

Can someone please help me? I’m a 32 y/o college student who’s spent 8 hours working on this but getting nowhere. My instructor just says ‘add this’ but doesn’t say where and I’m a very visual person so that doesn’t help!

package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    import flash.utils.getTimer;
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.net.URLRequest;

    public class bath2 extends MovieClip {
        var textDisplay:TextField;
        var bblue_bomb = new blue_bomb();
        var byellow_bomb = new yellow_bomb();
        var bgreen_bomb = new green_bomb();
        var borange_bomb = new orange_bomb();
        var bpurple_bomb = new purple_bomb();
        var bpink_bomb = new pink_bomb();

        // this is animation stuff
        private var speedx, speedy:Number;  //current speed, pixels per second
        private var lastTime:int;            //remember the last frame's time

        var bubble:Array = new Array();//holds color for array

        public function bath2() {
            bblue_bomb.x = 346.3;
            bblue_bomb.y = 134.2;
            byellow_bomb.x = 398.9;
            byellow_bomb.y = 164.3;
            bgreen_bomb.x = 367.8;
            bgreen_bomb.y = 285.0;
            borange_bomb.x = 202.4;
            borange_bomb.y = 272.2;
            bpurple_bomb.x = 140.5;
            bpurple_bomb.y = 257.2;
            bpink_bomb.x = 146.3;
            bpink_bomb.y = 152.1;
            
            addChild(bblue_bomb);
            addChild(byellow_bomb);
            addChild(bgreen_bomb);
            addChild(borange_bomb);
            addChild(bpurple_bomb);
            addChild(bpink_bomb);
        
            
            //fill bubble array
            bubble = ["blue","green","orange","magenta","purple","yellow"];

            textDisplay = new TextField();
            textDisplay.defaultTextFormat = new TextFormat("Porky's",23);
            textDisplay.x = 15;
            textDisplay.y = 25;
            textDisplay.width = 600;
            textDisplay.height = 200;
            textDisplay.textColor = 663399;
            textDisplay.selectable = false;
            textDisplay.text = "Click the first letter of the color!";
            addChild(textDisplay);

            //trace("Text: " + textDisplay.text);//debug line

            stage.addEventListener (KeyboardEvent.KEY_UP, pressKey);
        } // end of bath2
        
        public function bath2() {
            var somePictLdr:Loader = new Loader();
            var request:URLRequest = new URLRequest("octopus.jpg");
            somePictLdr.load(request);
            addChild(somePictLdr);
        }
        
        public function pressKey(event:KeyboardEvent) {
            var charPressed:String = (String.fromCharCode (event.charCode));
            var foundLetter:Boolean = false;

            for (var i:int=0; i<bubble.length; i++) {
                if (bubble*.charAt(0).toLowerCase() == charPressed) 
                {
                    //trace("Key Pressed:" + charPressed);//debug line
                    if (charPressed == "b")
                    {
                        for (var j:int=0; j<50;j++)
                        {
                            var bubble_Blue:blue_bubble = new blue_bubble();
                            bubble_Blue.x = Math.random()*600;
                            bubble_Blue.y = Math.random()*800;
                            addChild(bubble_Blue);
                            
                        } // end for..loop
                    }
                    if (charPressed =="g")
                    {
                    
                    for (var k:int=0; k<50;k++)
                        {
                            var bubble_Green:green_bubble = new green_bubble();
                            bubble_Green.x = Math.random()*600;
                            bubble_Green.y = Math.random()*800;
                            addChild(bubble_Green);
                            
                        } 
                    }
                    if (charPressed =="p")
                    {
                        
                        for (var l:int=0; l<50;l++)
                        {
                            var bubble_Purple:purple_bubble = new purple_bubble();
                            bubble_Purple.x = Math.random()*600;
                            bubble_Purple.y = Math.random()*800;
                            addChild(bubble_Purple);
                            
                        }
                    }
                    if (charPressed =="o")
                    {
                        for (var m:int=0; m<50;m++)
                        {
                            var bubble_Orange:orange_bubble = new orange_bubble();
                            bubble_Orange.x = Math.random()*600;
                            bubble_Orange.y = Math.random()*800;
                            addChild(bubble_Orange);
                            
                        }
                    }
                    if (charPressed =="y")
                    {
                        for (var n:int=0; n<50;n++)
                        {
                            var bubble_Yellow:yellow_bubble = new yellow_bubble();
                            bubble_Yellow.x = Math.random()*600;
                            bubble_Yellow.y = Math.random()*800;
                            addChild(bubble_Yellow);
                            
                        } // end for..loop
                    }
                    if (charPressed =="m")
                    {
                        for (var p:int=0; p<50;p++)
                        {
                            var bubble_Pink:pink_bubble = new pink_bubble();
                            bubble_Pink.x = Math.random()*600
                            bubble_Pink.y = Math.random()*800;
                            addChild(bubble_Pink);
                            
                        }
                    }
                    
                    textDisplay.text = bubble*;
                        
                    foundLetter = true;
                }// end if
            } // end for..loop
        } // end pressKey
        
        public function animatedBubble (x,y,dx,dy)
        {
            //set location and speed
            this.x = x;
            this.y = y;
            speedx = dx
            speedy = dy;
            lastTime = getTimer();
            
            
            //move each frame
            addEventListener (Event.ENTER_FRAME, moveObject);
            
        }// end of animated bubble
        
        public function moveObject(event:Event)
        {
            //get time passed
            var timePassed:int = getTimer() - lastTime;
            lastTime += timePassed;
            
            //update position according to speed and time
            this.x += speedx*timePassed/1000;
            this.y += speedy*timePassed/1000;
        }
        //end of moveObject
        
    } // end of class bath2
} // end of file



Thank you,

Jill