contact

Actionscript 3 3D with Flash CS4

I finally got a copy of adobe flash cs4. In addition to the great new user interface flash cs4 can compile flashplayer 10 content which enables the new actionscript 3 3D methods. with only the three simply rotationX, rotationY and rotationZ properties one can quickly create really nice 3D animations. This is my first test.

here are the few lines of code it took to make this thing spin:

</pre>
import flash.display.*
 import flash.geom.*
 import flash.events.*
 import flash.display.*
 var panes:MovieClip=new MovieClip()
 panes.x=300
 panes.y=200

for(var i:Number=0;i<18;i++){
 var pane:MovieClip=new MovieClip()
 pane.graphics.lineStyle(1,0xffffff,0.5)
 pane.graphics.beginFill(0x003366,0.3)
 pane.graphics.drawRect(0,0,100,100)

pane.x=0
 pane.y=-50

pane.rotationY=i*20
 pane.moving=false
 panes.addChild(pane)

}

addChild(panes)
 panes.rotationZ=90
 panes.cacheAsBitmap=true
 panes.addEventListener(Event.ENTER_FRAME,movePanes)

function movePanes(e:Event){
 panes.rotationX+=5
 }
<pre>

Tags: , , , , ,

  1. I cut and pasted the code in my CS4 IDE (running on Windows XP Pro).

    After retyping the little x (gives compiler error) in
    pane.graphics.beginFill(0

  2. HI

    I tried to fix the typo with the x but the sourcecode is fine, it seems my codeformatting plugin messes up some how.

    As for the strange behavior you describe, thats really strange. I am developing on mac so it might be os, but I kind of doubt it.
    maybe you can somehow try to force a refresh after each frame?
    Also try to simplify the code to a single rotating square and try to go from there?

    let me know how it went