away3d和cs6外部as3文件

时间:2013-04-24 18:15:49

标签: actionscript-3 flash away3d

我需要一些帮助午餐外部动作脚本文件让我说我有这个文件:

Basic_SkyBox.as

以及它的代码:

package
{
    import away3d.cameras.lenses.*;
    import away3d.containers.*;
    import away3d.entities.*;
    import away3d.materials.*;
    import away3d.materials.methods.*;
    import away3d.primitives.*;
    import away3d.textures.*;
    import away3d.utils.*;

    import flash.display.*;
    import flash.events.*;
    import flash.geom.Vector3D;

    [SWF(backgroundColor="#000000", frameRate="60", quality="LOW")]

    public class Basic_SkyBox extends Sprite
    {
        // Environment map.
        [Embed(source="../embeds/skybox/snow_positive_x.jpg")]
        private var EnvPosX:Class;
        [Embed(source="../embeds/skybox/snow_positive_y.jpg")]
        private var EnvPosY:Class;
        [Embed(source="../embeds/skybox/snow_positive_z.jpg")]
        private var EnvPosZ:Class;
        [Embed(source="../embeds/skybox/snow_negative_x.jpg")]
        private var EnvNegX:Class;
        [Embed(source="../embeds/skybox/snow_negative_y.jpg")]
        private var EnvNegY:Class;
        [Embed(source="../embeds/skybox/snow_negative_z.jpg")]
        private var EnvNegZ:Class;

        //engine variables
        private var _view:View3D;

        //scene objects
        private var _skyBox:SkyBox; 
        private var _torus:Mesh;

        /**
         * Constructor
         */
        public function Basic_SkyBox()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            //setup the view
            _view = new View3D();
            addChild(_view);

            //setup the camera
            _view.camera.z = -600;
            _view.camera.y = 0;
            _view.camera.lookAt(new Vector3D());
            _view.camera.lens = new PerspectiveLens(90);

            //setup the cube texture
            var cubeTexture:BitmapCubeTexture = new BitmapCubeTexture(Cast.bitmapData(EnvPosX), Cast.bitmapData(EnvNegX), Cast.bitmapData(EnvPosY), Cast.bitmapData(EnvNegY), Cast.bitmapData(EnvPosZ), Cast.bitmapData(EnvNegZ));

            //setup the environment map material
            var material:ColorMaterial = new ColorMaterial(0xFFFFFF, 1);
            material.specular = 0.5;
            material.ambient = 0.25;
            material.ambientColor = 0x111199;
            material.ambient = 1;
            material.addMethod(new EnvMapMethod(cubeTexture, 1));

            //setup the scene
            _torus = new Mesh(new TorusGeometry(150, 60, 40, 20), material);
            _view.scene.addChild(_torus);

            _skyBox = new SkyBox(cubeTexture);
            _view.scene.addChild(_skyBox);

            //setup the render loop
            addEventListener(Event.ENTER_FRAME, _onEnterFrame);
            stage.addEventListener(Event.RESIZE, onResize);
            onResize();
        }

        /**
         * render loop
         */
        private function _onEnterFrame(e:Event):void
        {
            _torus.rotationX += 2;
            _torus.rotationY += 1;

            _view.camera.position = new Vector3D();
            _view.camera.rotationY += 0.5*(stage.mouseX-stage.stageWidth/2)/800;
            _view.camera.moveBackward(600);

            _view.render();
        }

        /**
         * stage listener for resize events
         */
        private function onResize(event:Event = null):void
        {
            _view.width = stage.stageWidth;
            _view.height = stage.stageHeight;
        }
    }
}

好吧然后我创建新动作脚本页面如何引用上面的文件脚本在flash cs6中的项目主页面中运行?

1 个答案:

答案 0 :(得分:1)

您需要将Document Class设置为Basic_Skybox。确保.fla和Basic_Skybox.as位于同一目录中。

这是一个关于这样做的教程:http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/