flash effects with bitmapdata

Posted by druva | Flash, Flex, as3 | Sunday 7 February 2010 11:11 pm

Flash is great!!

This movie requires Flash Player 9

 

How to Create Falling Hearts with Flash CS4 Action Script AS3

Posted by druva | Flash, as3, utils | Saturday 6 February 2010 1:45 pm

This code show how to create falling hearts with flash cs4

you can also use the code for cs3
create a movieclip with a heart in your library

package {

	import flash.display.MovieClip;
	import flash.events.*;

	public class fallingheart extends MovieClip {
		public function fallingheart() {
			for (var i = 0; i < 30; i ++) {
				var h:heart = new heart();
				h.x=Math.round(Math.random()*stage.stageWidth);
				h.y=Math.round(Math.random()*stage.stageHeight);
				h.scaleX = h.scaleY = .4+ ((Math.random()*1)/2);
				h.swing = 15 + (Math.random()*15);
				h.n=Math.random()*2;
				h.speed = 1 + (Math.random()*4);

				addChild(h);
				h.addEventListener(Event.ENTER_FRAME, onEnterLoop);
				//h.onEnterFrame = fall;
			}
		}

		//--  you can also use timer to call this
		public function onEnterLoop(e:Event) {
			trace(stage.stageHeight);
			var h:heart=e.currentTarget as heart;
			h.y+=h.speed;
			h.n+=0.25;
			h.rotation=Math.cos(h.n)*h.swing;
			if (h.y>stage.stageHeight) {
				h.x=Math.round(Math.random()*stage.stageWidth);
				h.y=-50;
			}
		}
	}
}

This movie requires Flash Player 9

 

Get Even or Odd – getParity using Action Script AS

Posted by druva | Flash, Flex, JS, as2, as3, utils | Thursday 4 February 2010 3:12 am

The below code shows how to use the class


import druva.NumberUtil;

trace('500', NumberUtil.getParity(500));
// true
trace('489', NumberUtil.getParity(489));
// false
trace('5', NumberUtil.getParity(5));
//false
trace('1', NumberUtil.getParity(1));
//true
trace('400', NumberUtil.getParity(400));
//false

This is the actual class


package druva {
  import flash.display.Sprite;

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

    public static function getParity(num:Number):String {
		return (num % 2) ? 'odd' : 'even';
	}

  }
}
 

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
		}
	}
}
 

get Random Number Between using Actionscipt AS3

Posted by druva | Flash, as3, utils | Tuesday 2 February 2010 12:03 am

The below code shows how to use the class


import druva.NumberUtil;
trace(NumberUtil.getRand(5, 10));

This is the actual class for validation


package druva{
	import flash.display.Sprite;

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

		public static function getRand(min:Number, max:Number):Number {
			return Math.floor(Math.random()*(max+1-min))+min;
		}

	}
}
 

glyph using action script

Posted by Vineela | Flash, as3, utils | Monday 1 February 2010 4:10 am

import flash.display.Sprite;
import flash.text.*;

function glyph(){
	var strFontName:String = "Wingdings";
	var givenFont:Font;
	var enumeratedfonts:Array = Font.enumerateFonts(true);

	for (var i:int = 0; i < enumeratedfonts.length; i++) {
		if (enumeratedfonts[i].fontName == strFontName) {
			givenFont = enumeratedfonts[i];
			break;
		}
	}
	trace(givenFont.hasGlyphs("blog.totusinfo.com"));
}

glyph();
 
« Previous Page