AS3 newbie, help needed please

Hi,

I’m really in need of some help. I am trying to put together a papervision site together. This obviously means using as3. I am fairly new to as3 and need to start from scratch. But this project requires some speed so I do not have time :frowning: yet.

I have cobble some bits together but the issue I’m having an issue and wondered if anyone could help.

I have defined some buttons on a face of the papervision model, which work, as I have managed to get the functions to trace.

I have also added a movie clip to the stage and defined its name. This is all in the same public class.

The buttons that are in papervision cube work from functions are outside of this class. They are recognized by the event listeners inside of the class.

When clicked I want the button in the cube to make the movie clip work which i added earlier work.

The issue is, inside the class where the movie clip was added to the stage, I can target the instance name.

Outside of the class where the button functions are, I get an error saying it is not recognized.

If I try to put the button functions inside the class I also get a message saying they are not allowed inside the class basically.

So I am stuck.

I there a way of calling the instance which was specified in a class froma function outside the class?

I know this may be confusing for you, but I’ll put the code up for anyone who would be kind enough to help.

package com.guinetik.ppv3dcube 
{
    
    // FLASH IMPORTS
    
    import flash.display.SimpleButton;
    import flash.display.Sprite;
    
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    import com.guinetik.ppv3dcube.elements.Input;
    import flash.ui.Keyboard;
    
    // PAPERVISION IMPORTS
    
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.Papervision3D;
    import org.papervision3d.events.InteractiveScene3DEvent;
    import org.papervision3d.materials.MovieMaterial;

    // TWEENLITE IMPORT
    
    import gs.TweenLite;
    import fl.motion.easing.*;
    
    // The CubeWebsite class should be used as a Document Class for any .FLA file
    
    public class CubeWebsite extends Sprite
    {
        
        // Background Graphics
        private var bg                            :BG                            = new BG();
        
        // PAPERVISION ELEMENTS
        
        
        // The container is a viewport3d object, the class in which everything will be rendered into
        private var container                    :Viewport3D;
        
        // The scene is the papervision object in which everything happens. The stage
        private var scene                        :Scene3D;
        
        // The camera object is the viewpoint of a scene. Controls the distance from the object
        private var camera                        :Camera3D;
        
        // The render engine is responsible for displaying things on the viewport
        private var render_engine                :BasicRenderEngine;
        
        // This is our cube object in where we'll attach our sections
        private var site                        :Cube;
        
        // MENU AND BUTTONS
        
        private var menu                        :Menu                        = new Menu();
        
        private var bt1                            :SimpleButton;
        private var bt2                            :SimpleButton;
        private var bt3                            :SimpleButton;
        private var bt4                            :SimpleButton;
        private var bt5                            :SimpleButton;
        private var bt6                            :SimpleButton;
        
        // BODY SET UP
            
        
        // CONSTANTS. If you change the dimensions of the sections, please update here
        
        public static const SITE_WIDTH            :Number                        = 285;
        public static const SITE_HEIGHT            :Number                        = 285;
        private var input:Input;
        
        public function CubeWebsite() 
        {
            
            
            // STAGE ALIGNMENT AND SCALE
            
            stage.align                         = "TL";
            stage.scaleMode                     = "noScale";
            
            stage.addEventListener(Event.RESIZE, resize);
            
            addChildAt(bg, 0);
            
            addChild(menu);
            
            menu.y                                = 520;

            
            // STAGE ALIGNMENT AND SCALE
            
            var mc:                        Body                        =new Body();
            
            mc.x=30;
            mc.y=30;
            
            addChild(mc);
        
            
            // Here we treat the menu objects like this class' objects
            
            bt1                                 = menu.bt1;
            bt2                                 = menu.bt2;
            bt3                                 = menu.bt3;
            bt4                                 = menu.bt4;
            bt5                                 = menu.bt5;
            bt6                                 = menu.bt6;
            
            // Adding onClick event listeners
            
            bt1.addEventListener(MouseEvent.CLICK, openFront);
            bt2.addEventListener(MouseEvent.CLICK, openBack);
            bt3.addEventListener(MouseEvent.CLICK, openRight);
            bt4.addEventListener(MouseEvent.CLICK, openLeft);
            bt5.addEventListener(MouseEvent.CLICK, openTop);
            bt6.addEventListener(MouseEvent.CLICK, openBottom);
            
            // PAPERVISION SET UP
            
            
            // This sets off all trace actions of papervision. If you want to debug something, set this true
            Papervision3D.VERBOSE                 = false;
            
            // Create a new container object. The parameters are width and height, auto stage scale and interactive
            container                             = new Viewport3D(0, 0, false, true);
            
            // Create a new scene 3d object
            scene                                 = new Scene3D();
            
            // Create a new camera3d object
            camera                                = new Camera3D();
            
            // Create a new render. Since we want to save some performance, let's use the BasicRenderEngine
            render_engine                        = new BasicRenderEngine();
            
            // Set our zoom to 11. If you change the dimensions of the sections, you might want to test another values for here
            camera.zoom                         = 11;
            
            
            // Adds our viewport to the display list
            addChildAt( container, 1 );

            // MATERIALS SET UP
            
            // The first thing to do is to create a new instance of each section of the site
            
            var frontpage                        :FrontPage                 = new FrontPage();
            var about                            :AboutUs                 = new AboutUs();
            var services                        :Services                 = new Services();
            var projects                        :Projects                 = new Projects();
            var topImage                        :TopImage                 = new TopImage();
            var bottomImage                        :BottomImage             = new BottomImage();
            
            // The cube in papervision3d is a set up of 6 materials (textures). 
            // Since we are working with movieclips from the library,
            // our materials will be MovieMaterials objects
            // The parameters are: transparent, animated (timeline) and precise (creates the material from an instance)
            
            var front                            :MovieMaterial             = new MovieMaterial(frontpage, true, true, true);
            var back                            :MovieMaterial             = new MovieMaterial(about, true, true, false);
            var right                            :MovieMaterial             = new MovieMaterial(services, true, true, false);
            var left                            :MovieMaterial             = new MovieMaterial(projects, true, true, false);
            var top                                :MovieMaterial             = new MovieMaterial(topImage, true, true, false);
            var bottom                            :MovieMaterial             = new MovieMaterial(bottomImage, true, true, false);

            front.animated = true;
            front.interactive = true;
            
            //
            var btn1:SimpleButton;
            var btn2:SimpleButton;
            var btn3:SimpleButton;
            
            btn1 = frontpage.btn1;
            btn2 = frontpage.btn2;
            btn3 = frontpage.btn3;
            
            btn1.addEventListener(MouseEvent.CLICK, page1ClickEvent);
            btn1.addEventListener(MouseEvent.MOUSE_OVER, page1OverEvent);
            btn1.addEventListener(MouseEvent.MOUSE_OUT, page1OffEvent);
            //
            btn2.addEventListener(MouseEvent.CLICK, page2ClickEvent);
            btn2.addEventListener(MouseEvent.MOUSE_OVER, page2OverEvent);
            btn2.addEventListener(MouseEvent.MOUSE_OUT, page2OffEvent);
            
            btn3.addEventListener(MouseEvent.CLICK, page3ClickEvent);
            btn3.addEventListener(MouseEvent.MOUSE_OVER, page3OverEvent);
            btn3.addEventListener(MouseEvent.MOUSE_OUT, page3OffEvent);
            
            // The next thing to do is to create a list of materials that will
            // generate our cube. Pass all the values created previously
            var materials                         :MaterialsList             = new MaterialsList({front:front, back:back, right:right, left:left, top:top, bottom:bottom});
            
            
            // CUBE SET UP
            
            // Here we create a new cube based on the sections' dimensions and the materials. 
            // The last parameters are the segments parameters. Change this will aftect the rendering. A greater
            // value, the rendering will be more precise, but slower and vice-versa
            
            site                                 = new Cube( materials, SITE_WIDTH, SITE_WIDTH, SITE_HEIGHT, 1, 1, 1);
            
            // Here we set the rotation so it'll load on the FrontPage side
            site.z                                 = 285*.5;
            site.rotationX                         = -180;
            site.rotationZ                         = 180;
            scene.addChild( site, "site" );
            
            // EXTRA STUFF
            
            TweenLite.defaultEase                 = Back.easeInOut;
            
            addEventListener( Event.ENTER_FRAME, render );
            resize(null);
            
            this.visible                        = false;
            
            init();
            

            
        }
                    
        
        //SUB MENU SETUP

        
        
        public function page1ClickEvent(event:Event):void{
            trace(CubeWebsite);
        }
        
        public function page1OverEvent(event:Event):void{
            trace("mouse rolledOver me");
        }
        
        public function page1OffEvent(event:Event):void{
            trace("mouse rolledOff me");
        }
        
        public function page2ClickEvent(event:Event):void{
            trace("mouse clicked on me");
        }
        
        public function page2OverEvent(event:Event):void{
            trace("mouse rolledOver me");
        }
        
        public function page2OffEvent(event:Event):void{
            trace("mouse rolledOff me");
        }
        
        public function page3ClickEvent(event:Event):void{
            trace("mouse clicked on me");
        }
        
        public function page3OverEvent(event:Event):void{
            trace("mouse rolledOver me");
        }
        
        public function page3OffEvent(event:Event):void{
            trace("mouse rolledOff me");
        }
        

        public function init():void
        {
            
            this.visible                        = true;
            
            // This is a simple animation to start the cube from the center and then start the buttons from the top
            
            TweenLite.from(site, 3,             {rotationX:-90, rotationY:0, rotationZ:-180, z:SITE_WIDTH, scaleX:0, scaleY:0, scaleZ:0});
            TweenLite.from(bt1, 1.0,             {y:90, delay:2.5});
            TweenLite.from(bt2, 1.0,             {y:90, delay:2.7});
            TweenLite.from(bt3, 1.0,             {y:90, delay:2.9});
            TweenLite.from(bt4, 1.0,             {y:90, delay:3.1});
            TweenLite.from(bt5, 1.0,             {y:90, delay:3.3});
            TweenLite.from(bt6, 1.0,             {y:90, delay:3.5});
            
        }
        
        // STAGE RESIZER
        
        private function resize(e:Event):void
        {
            
            var stage_width:Number                 = stage.stageWidth;
            var stage_height:Number             = stage.stageHeight;
            
            bg.width                            = stage_width;
            bg.height                            = stage_height;
            
            // CENTRALIZING THE CONTAINER
            
            container.viewportWidth             = stage_width;
            container.viewportHeight             = stage_height;

            container.containerSprite.x         = int( stage_width * .7 );
            container.containerSprite.y         = int( stage_height * .5 - 20 );
            
            menu.x                                = int((stage.stageWidth - menu.width) - 20);
            
        }
        
        // RENDERING THE ENGINE
        
        private function render( event :Event ):void 
        {

            render_engine.renderScene(scene, camera, container);

        }
        
        // BUTTON ACTIONS
        
        // These actions will rotate the cube according to the section
        // Each section is located on one face of the cube, so rotating it will allow us to change the cube's point of view.
        // It's about the same thing for all sides, but try to experiment your own values to see something different.
        
        private function openFront(e:MouseEvent):void
        {
            
            TweenLite.to(site, 2,                 {rotationX:-180, rotationZ:180, rotationY:0, z:SITE_WIDTH/2});
            
        }

        private function openBack(e:MouseEvent):void
        {
            
            TweenLite.to(site, 2,                {rotationX:-180, rotationZ:180, rotationY:180, z:SITE_WIDTH/2});
            
        }

        private function openRight(e:MouseEvent):void
        {
            
            TweenLite.to(site, 2,                 {rotationX:0, rotationY:90, rotationZ:0, z:SITE_WIDTH/2});
            
        }

        private function openLeft(e:MouseEvent):void
        {
            
            TweenLite.to(site, 2,                 {rotationX:0, rotationY:-90, rotationZ:0, z:SITE_WIDTH/2});
            
        }

        private function openTop(e:MouseEvent):void
        {
            
            TweenLite.to(site, 2,                 {rotationX:90, rotationY:0, rotationZ:0, z:SITE_WIDTH});
            
        }

        private function openBottom(e:MouseEvent):void
        {
            
            TweenLite.to(site, 2,                 {rotationX:-90, rotationY:0, rotationZ:-180, z:SITE_WIDTH});
            
        }
        
    }
    
}


The bits I am struggling with are getting the function:

public function page1ClickEvent(event:Event):void{
            mc.gotoAndStop(2);
        }

to target ‘mc’ which was specified in public function CubeWebsite()

Thanks in advance.