Adobe Air,AS3,Flash

Find extension of a file

14 Apr , 2013  

 /**
 *
 * find extension of a file
 */
 private function findExtension(str : String) : String
 {
 return String(str.split(".")[1]).toLowerCase();
 }

Uncategorized

Resize image to fit in a rectangle

14 Apr , 2013  

/**
 * resize image to fit in a rectangle
 */
 public function resizeToFit(mc : MovieClip, width : Number, height : Number) : void
 {
 var largeWidth : Number = mc.width;
 var largeHeight : Number = mc.height;
initialContainerWidth = largeWidth;
 initialContainerHeight = largeHeight;
mc.width = int((fitPercent / 100) * largeWidth);
 mc.height = int((fitPercent / 100) * largeHeight);
 mc.x = Math.round((componentWidth - mc.width) / 2);
 mc.y = Math.round((componentHeight - mc.height) / 2);
 }

AS3,Flash

Set the movieclip color

14 Apr , 2013  

/**
 * set the movie clip color
 */
 public function setColor(mc : MovieClip, color : Number) : void
 {
 var colorTransform : ColorTransform = mc.transform.colorTransform;
 colorTransform.color = color;
 mc.transform.colorTransform = colorTransform;
 }

AS3,Away3D,Flash

Cube with different color faces

8 Feb , 2013  

public class away3DBasico_v003 extends Sprite
 {
   public var view:View3D = new View3D();

   public var plano1:PlaneGeometry = new PlaneGeometry(100,100,1,1,true);//false indica si el plano esta acostado o parado
   public var plano2:PlaneGeometry = new PlaneGeometry(100,100,1,1,true);//estos dos estaran de huevones acostados
   public var plano3:PlaneGeometry = new PlaneGeometry(100,100,1,1,false);
   public var plano4:PlaneGeometry = new PlaneGeometry(100,100,1,1,false);
   public var plano5:PlaneGeometry = new PlaneGeometry(100,100,1,1,false);
   public var plano6:PlaneGeometry = new PlaneGeometry(100,100,1,1,false);

   private var plano_m1:ColorMaterial;
   private var plano_m2:ColorMaterial;
   private var plano_m3:ColorMaterial;
   private var plano_m4:ColorMaterial;
   private var plano_m5:ColorMaterial;
   private var plano_m6:ColorMaterial;

   public var malla1:Mesh;
   public var malla2:Mesh;
   public var malla3:Mesh;
   public var malla4:Mesh;
   public var malla5:Mesh;
   public var malla6:Mesh;

   //public var vector3d:Vector3D = new Vector3D(5,5,0,1);
   public var contenedor:ObjectContainer3D =new ObjectContainer3D();

   public function away3DBasico_v003()
   {

   view.backgroundColor= 0xB0C4DE;
  plano_m1= new ColorMaterial(0x000fff);
   plano_m2= new ColorMaterial(0xfff000);
   plano_m3= new ColorMaterial(0xffcc00);
   plano_m4= new ColorMaterial(0x909090);
   plano_m5= new ColorMaterial(0x008000);
   plano_m6= new ColorMaterial(0xff0000);

   malla1 = new Mesh(plano1,plano_m1);
   malla2 = new Mesh(plano2,plano_m2);
   malla3 = new Mesh(plano3,plano_m3);
   malla4 = new Mesh(plano4,plano_m4);
   malla5 = new Mesh(plano5,plano_m5);
   malla6 = new Mesh(plano6,plano_m6);

   addChild(view);

   malla1.y+=50;//cara superior
   malla2.rotationZ=180;malla2.y-=50;//cara inferior
   malla3.z-=50;//cara frontal
   malla4.rotationY=180;malla4.z+=50//cara atras
   malla5.rotationY=90;malla5.x=-50; //cara derecha
   malla6.rotationY=270;malla6.x=50; //cara izquierda

   view.camera.y+=100;
   view.camera.z+=300;

   contenedor.addChild(malla1);
   contenedor.addChild(malla2);
   contenedor.addChild(malla3);
   contenedor.addChild(malla4);
   contenedor.addChild(malla5);
   contenedor.addChild(malla6);

   view.scene.addChild(contenedor);

   contenedor.pivotPoint = new Vector3D(0,1,0);

   this.addEventListener(Event.ENTER_FRAME, loop);

   }

   public function loop(e:Event):void
   {

   contenedor.rotationY+=1;

   view.camera.y = 3 * (stage.mouseY - stage.stageHeight/2);
   view.camera.x = -3 * (stage.mouseX - stage.stageHeight/2);
   view.render();
   }
 }

AS3,Away3D,Flash

Away3d 4 Beta: Bitmap texture with loaded image

8 Feb , 2013  

// creating the mesh
var geometry:SphereGeometry = new SphereGeometry (100);
var sphere:Mesh = new Mesh(geometry);
scene.addChild(sphere);

// loading texture
var url:String = 'image.jpg';
var Ldr:Loader = new Loader();
Ldr.load(new URLRequest(url));
Ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onComplete(e:Event):void
{
     var bitmap:Bitmap = Bitmap(Ldr.content);
     var bitmapData:BitmapData = bitmap.bitmapData;
     var texture:BitmapTexture = new BitmapTexture(bitmapData);
     var material:TextureMaterial = new TextureMaterial();
     material.texture = texture;
     sun.material = material;
}

AS3

Create a square in AS3

8 Feb , 2013  

var square:Sprite = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,100,100);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;