1 Package2 {3 ImportFlash.display.Sprite;4 Importflash.events.Event;5 ImportFlash.geom.Vector3D;6 ImportFlash.text.TextField;7 ImportFlash.text.TextFormat;8 9 /**Ten * @author Frost.yen One * @e-mail [email protected] A * @create 2015-9-2 pm 3:17:09 - * - */ the[SWF (width=" the", height=" the")] - Public classDrawcubeextendsSprite - { - Private var_facearr:array = []; + Private var_sidelen: Number= 100;//Square side Length - Private var_container:sprite; + Private var_text:string ="As the world Hello"; A Private var_tf:textformat =NewTextFormat ("Microsoft Jas Black", 60,0xff0000); at Public functionDrawcube () - { - initviews (); - initeventlisteners (); - } - Private functionInitviews ():void in { -_container =NewSprite (); to_container.x = 300; +_CONTAINER.Y = 300; - This. AddChild (_container); the Creatcube (); * } $ Private functionIniteventlisteners ():voidPanax Notoginseng { - This. AddEventListener (event.enter_frame,onmove); the } + Private functionOnMove (e:event):void A { the for(varI:int = 0;i<6;i++){ +_facearr[i].transform.matrix3d.appendrotation ((mousex-_container.x)/50,vector3d.y_axis); -_facearr[i].transform.matrix3d.appendrotation ((_container.y-mousey)/50,vector3d.x_axis); $ } $_facearr.sorton ("Z", 18); - for(i=0;i<_facearr.length;i++){ - _container.setchildindex (_facearr[i],i); the } - }Wuyi Private functionCreatcube ():void the { - for(vari:int=0;i<6;i++){ Wu varRect:sprite = DrawRect (_sidelen,_sidelen,math.random () *0xffffff); - varTxt:textfield =NewTextField (); About _container.addchild (rect); $ rect.addchild (TXT); -Txt.autosize ="Center"; -Txt.selectable =false; -Txt.defaulttextformat =_TF; ATxt.text = _text.substr (i,1); +Txt.x =-txt.width*0.5; theTxt.y =-txt.height*0.5; -Rect.z =-_sidelen/2; $_facearr[i] =rect; theI<4?rect.transform.matrix3d.appendrotation (90*i,vector3d.y_axis): 0; the } the_facearr[4].transform.matrix3d.appendrotation (-90, Vector3d.x_axis); the_facearr[5].transform.matrix3d.appendrotation (90, Vector3d.x_axis); - } in Private functionDrawRect (Width: Number, Height: Number, Color:uint): Sprite the { the varRect:sprite =NewSprite (); AboutRect.graphics.beginFill (color,0.9); theRect.graphics.drawRect (-width*0.5,-height*0.5, width,height); the Rect.graphics.endFill (); the returnrect; + } - } the}
[ActionScript 3.0] AS3 Drawing Cubes