正在阅读:Flash实例教程:AS3.0打造三维旋转球Flash实例教程:AS3.0打造三维旋转球

2009-11-28 09:56 出处:PConline 作者:中国教程网论坛 责任编辑:lizhiyan

  5、添加as层输入代码:

//导入BitmapSphereBasic类 

import com.flashandmath.cs4.BitmapSphereBasic; 

//创建一个行星 

var board:Sprite = new Sprite(); 

//添加到显示列表 

this.addChild(board); 

//生成 datatype BitmapSphereBasic 的一个函数。 

// 设定函数初始值。 

var ball:BitmapSphereBasic; 

//旋转的一个布尔值的函数。 

var autoOn:Boolean = true; 

//两个函数为鼠标旋转。 

var prevX:Number; 

var prevY:Number; 

//行星的位置. 

var ballX:Number = 250; 

var ballY:Number = 250; 

//贴图 

var imageData:BitmapData = new Earth(800,548); 

ball = new BitmapSphereBasic(imageData); 

board.addChild(ball); 

ball.x = ballX; 

ball.y = ballY; 

//滤镜 

ball.filters = [new GlowFilter(0xB4B5FE,0.6,32.0,32.0,1)]; 

this.addEventListener(Event.ENTER_FRAME,autoRotate); 

board.addEventListener(MouseEvent.ROLL_OUT,boardOut); 

board.addEventListener(MouseEvent.MOUSE_MOVE,boardMove); 

board.addEventListener(MouseEvent.MOUSE_DOWN,boardDown); 

board.addEventListener(MouseEvent.MOUSE_UP,boardUp); 

function autoRotate(e:Event):void { 

        if (autoOn) { 

                ball.autoSpin(-1); 

 

        } 

 

//三个侦听为旋转和鼠标。 

function boardOut(e:MouseEvent):void { 

        autoOn = true; 

 

function boardDown(e:MouseEvent):void { 

        prevX = board.mouseX; 

        prevY = board.mouseY; 

        autoOn = false; 

 

function boardUp(e:MouseEvent):void { 

        autoOn = true; 

 

function boardMove(e:MouseEvent):void { 

        var locX:Number = prevX; 

        var locY:Number = prevY; 

        //取反 

        if (! autoOn) { 

                prevX = board.mouseX; 

                prevY = board.mouseY; 

                ball.rotateSphere(prevY - locY, - (prevX - locX),0); 

                e.updateAfterEvent(); 

 

        } 

}

  6、把附件中的com解压到同一目录下,完工测试。

  Dot.rar

  com.rar

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品