How to Convert TextField to Bitmap using Flash and AS3

Posted by druva | Flash, Flex, as3, utils | Wednesday 3 February 2010 10:15 pm

Convert TextField to Bitmap

package {
	import flash.display.*;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;

	public class BitmapUtils extends Sprite {
		public function BitmapUtils() {
			addChild(tf2bm('Druva'));
		}
		public function tf2bm(str:String) {
			var fmt:TextFormat;
			var bmd:BitmapData;
			var bm:Bitmap;
			var tf:TextField;

			fmt = new TextFormat();
			fmt.font='Verdana';
			fmt.size=30;

			tf = new TextField();
			tf.text=str;
			tf.setTextFormat(fmt);
			tf.autoSize=TextFieldAutoSize.LEFT;
			bmd=new BitmapData(tf.width,tf.height,true,0);
			bmd.draw(tf);
			bm=new Bitmap(bmd);
			bm.smoothing=true;
			return bm
		}
	}
}
 

Load Date from XML File using flash actionscript AS3

Posted by druva | Experiments, Flash, Flex, as3, utils | Wednesday 27 January 2010 1:42 pm

Simple Example to show how to load xml

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    public class DocumentClass extends Sprite
    {
        private var loader:URLLoader;
        private var xmlPath:URLRequest;

        public function DocumentClass()
        {
	 xmlPath = new URLRequest("http://server.com/xml.xml")
	loader = new URLLoader(xmlPath);
            loader.addEventListener(Event.COMPLETE, completeListener);
            loader.addEventListener(ProgressEvent.PROGRESS, progressListener);
        }

        private function completeListener(event:Event):void
        {
            trace(" all done loading " + loader.data + " and here's the xml file we loaded ");
        }

        private function progressListener(event:Event):void
        {
            trace(" loading.... " + loader.bytesLoaded + " / " + loader.bytesTotal + " bytes");
        }
    }
}
 

Create Color Wheel using Flex (Actionscript) AS3

Posted by druva | Flash, Flex, MXML, as3, utils | Sunday 24 January 2010 9:34 am

Working on color wheel i hope it looks good.
Cick to view working sample

 

Validate Email without RegExp in AS2 and AS3 in Flash

Posted by druva | Flash, Flex, as2, as3, utils | Tuesday 5 January 2010 12:22 am

The below code shows how to use the class


import druva.emailValidator;

trace('druva.flash@gmail.com > '+emailValidator.isValid('druva.flash@gmail.com'));
// true
trace('druva.flash@gmail > '+emailValidator.isValid('druva.flash@gmail'));
// false
trace('druva.@.com > '+emailValidator.isValid('druva.@.com'));
//false
trace('druva.@gmail.com > '+emailValidator.isValid('druva.@gmail.com'));
//true
trace('.aa@gmailcom > '+emailValidator.isValid('.aa@gmailcom'));
//false

This is the actual class for validation


package druva {
  import flash.display.Sprite;

  public class emailValidator extends Sprite{
    public function emailValidator(){
    }

    public static function isValid(em:String):Boolean {

        var sEmail:String = new String(em);
        var validEmail:Boolean = true;
        var numDotPos:int = sEmail.indexOf("@");
        var nDotIndex:int = sEmail.lastIndexOf(".");
        if(numDotPos == -1 || nDotIndex == -1) {
          validEmail = false;
        }
        if(!(numDotPos > 0)) {
          validEmail = false;
        }
          if(!(nDotIndex > numDotPos)) {
        validEmail = false;
        }
        if(!(numDotPos < sEmail.length - 1) || !(nDotIndex > numDotPos + 1)) {
          validEmail = false;
        }
        return validEmail;
    }

  }
}
 

Draw 3D Wedge using Flash Actinscript 2.0

Posted by druva | Flash, as2, utils | Thursday 30 July 2009 12:52 am

Hi
I hope this may be useful to some one

This movie requires Flash Player 9

source

 

Create Water Bubbles using Flash Actionscript 3.0 (AS3)

Posted by druva | Flash, as3, utils | Tuesday 17 February 2009 2:31 am

This a small example that shows how to create bubbles in flash


var bubbleCount:Number = 30;
var mWidth:Number = Stage.width;
var mHeight:Number = Stage.height;
var i = 0;
var minSpeed:Number = 2;

for (var i=0;i<bubbleCount;i++) {
 var bubble = this.attachMovie("bubble", "bubble" + i, i);

 bubble._x = Math.random() * mWidth;
 bubble._y = Math.random() * mHeight;
 bubble._xscale =  bubble._yscale =  bubble._alpha = 40 + Math.random() * 60;

 bubble.yspeed = Math.random() * 3 + minSpeed;
 bubble.onEnterFrame = function ()
 {
 this._y = this._y - this.yspeed;
 if (this._y <= 0)
 {
 this._y = 400;
 this._x = 10 + Math.random() * mWidth;
 }
 if (this._x >= mWidth || this._x <= 0)
 {
 this._y = 400;
 this._x = 10 + Math.random() * mWidth;
 }
 };

}

This is sample application with above code

This movie requires Flash Player 9

download source

 

How to Draw a Circle with Flash Actionscript 3.0 – AS3

Posted by Vineela | Flash, Flex, as3, utils | Sunday 4 January 2009 1:14 pm
package druva {

 import flash.display.*;

 public class drawCircle extends Sprite {

 public function drawCircle() {
 var canvas:Shape = new Shape(  );
 canvas.graphics.lineStyle(3, 0xFF0000);
 canvas.graphics.drawCircle(100,100,50);
 addChild(canvas);

 }
 }
}