New to AC3 having trouble with some basic principals

Im an C++ and php coder trying to break into AC3 and flash. The coding side of ac3 is straightforward enough its the flash intergration that im having trouble with.

For instance I`ve been trying to get the example code at the bottom to work.

I save it out as main.as in my working folder.

I add a movie clip to my main layer with the instance name of ship_mc

then on the first frame of my actions layer I add the following code


 
import main;
var mainloop:Mainloop3 = new Mainloop3();
addChild(mainloop);
 

flash kicks out the error:


1046: Type was not found or was not a compile-time constant: Mainloop3.
1180: Call to a possibly undefined method Mainloop3.

I know im missing something simple, I dont have a problem with the code itself, its getting flash to behave itself. If I put the code in the timeline it doesnt work as then the packages are nested.

If I try the method where I make main.as the document class for the stage it kicks out even more errors.

I get the feeling the code needs to be attached to ship_mc somehow but I cant find how to do that in the flash interface…

If someone could point out the obvious error for me I`d appreciate it. Thanks

example code:


[SIZE=4][COLOR=blue]package  {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    import flash.display.MovieClip;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    import flash.events.*;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    public class Mainloop3 extends MovieClip {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        static const RIGHT = 37;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        static const LEFT = 39;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        static const UP = 38;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        private var keyPressedRight:Boolean;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        private var keyPressedLeft:Boolean;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        private var keyPressedUp:Boolean;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        private var shipIncrement:int=0;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        public function Mainloop3() {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        addEventListener(Event.ENTER_FRAME, run);[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        stage.addEventListener(KeyboardEvent.KEY_UP,keyUpListener);[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        ship_mc.nextrotation=ship_mc.rotation;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        ship_mc.dx=0;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        ship_mc.dy=0;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        ship_mc.speed=.2;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        ship_mc.nextx=ship_mc.x;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        ship_mc.nexty=ship_mc.y;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        function run(e:Event):void {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            getKeys();[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            moveObjectsInMemory();[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            render();[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        function keyDownListener(e:KeyboardEvent):void {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            switch (e.keyCode) {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                case LEFT: [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    keyPressedRight=true;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    break;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                case RIGHT:[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    keyPressedLeft=true;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    break;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                case UP:[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    keyPressedUp=true;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    break;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        function keyUpListener(e:KeyboardEvent):void {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            switch (e.keyCode) {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                case LEFT: [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    keyPressedRight=false;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    break;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                case RIGHT:[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    keyPressedLeft=false;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    break;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                case UP:[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    keyPressedUp=false;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                    break;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        function getKeys() {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            shipIncrement=0;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            if (keyPressedRight) {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                shipIncrement=5;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            }else if(keyPressedLeft) {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                shipIncrement=-5;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            if (keyPressedUp) {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                ship_mc.dx=ship_mc.dx+ship_mc.speed*(Math.cos(2.0*Math.PI*(ship_mc.rotation-90)/360.0))[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]                ship_mc.dy=ship_mc.dy+ship_mc.speed*(Math.sin(2.0*Math.PI*(ship_mc.rotation-90)/360.0))[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        function moveObjectsInMemory() {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            ship_mc.nextrotation=ship_mc.rotation+shipIncrement;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            ship_mc.nextx=ship_mc.x+ship_mc.dx;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            ship_mc.nexty=ship_mc.y+ship_mc.dy;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]           if (ship_mc.nextx < 0) ship_mc.nextx=300;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            if (ship_mc.nextx > 300) ship_mc.nextx=0;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            if (ship_mc.nexty < 0) ship_mc.nexty=300;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            if (ship_mc.nexty > 300) ship_mc.nexty=0;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        function render() {[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            ship_mc.rotation=ship_mc.nextrotation;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            ship_mc.x=ship_mc.nextx;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]            ship_mc.y=ship_mc.nexty;[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]        }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    }[/COLOR][/SIZE]
[SIZE=4][COLOR=blue]    [/COLOR][/SIZE]
[SIZE=4][COLOR=blue]}[/COLOR][/SIZE]