Create Snowfall Easily in Flash CS4

Posted by druva | Flash, as3, utils | Thursday 31 December 2009 1:51 pm

This code show how to create snowfall in flash cs4

u can also use the code for cs3

package {

	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import druva.NumberUtil;
	import flash.utils.Timer;
	import flash.events.*;

	public class snowfall extends MovieClip {

		private var t:Timer;

		public function snowfall():void {
			t=new Timer(80);
			t.addEventListener(TimerEvent.TIMER, createParticle);
			t.start();
		}

		private function createParticle(e:TimerEvent) {

			var mc_particle:MovieClip =new MovieClip();
			mc_particle.graphics.beginFill(0xFFFFFF,1);
			mc_particle.graphics.drawCircle(0, 0, NumberUtil.getRand(3,5));
			mc_particle.graphics.endFill();

			mc_particle.x=NumberUtil.getRand(-60,600);
			mc_particle.wind = (NumberUtil.getRand(0,1) == 1) ?  'left' : 'right';
			mc_particle.filters=[new BlurFilter(10,10,2)];
			mc_particle.addEventListener(Event.ENTER_FRAME, moveParticle);
			addChild(mc_particle);

		}

		function moveParticle(e:Event):void {
			var targ:MovieClip=MovieClip(e.target);

			if (targ.y>400) {
				targ.removeEventListener(Event.ENTER_FRAME,moveParticle);
				removeChild(targ);
				return;
			}

			targ.y += 1;

			if (targ.wind=='left') {
				targ.x += 0.4;
			} else if (targ.wind== 'right') {
				targ.x -= 0.4;

			}

		}

	}
}

This movie requires Flash Player 9

 

Determine Easily What Image Formats the Target Device Supports

Posted by druva | Flash, as2, as3, utils | Tuesday 22 December 2009 1:12 am

You can check before loading the image with System.capabilities

if (System.capabilities.imageMIMETypes["image/png"]) {
 loadMovie("images/image.png", "mc_myPngImage");
}
 

Create Rounded Corners Rectangle with Actionscript 3.0 – AS3

Posted by druva | Flash, Flex, as3, utils | Saturday 7 November 2009 8:14 am

Rounded Corner Rectangle

import flash.display.*;

function round_rectangle(){

var shape:Shape = new Shape();
addChild(shape);

shape.graphics.beginFill(0xFF0000FF, 1.0);

shape.graphics.drawRoundRect(50, 10, 200, 100, 30, 30);

shape.graphics.endFill();
}

round_rectangle();

(more…)

 

using multiple values in trace()

Posted by druva | Flash, as3, utils | Tuesday 19 May 2009 12:50 am

in as3 trace you can pass multiple values without using ‘+’ operator

var a =1;
var b=2;
var c = 3;

trace(a, b, c);
//ouput 1 2 3

 

Open PoPup From Flash

Posted by druva | Flash, Flex, as3, utils | Friday 20 March 2009 1:21 pm
var b:Button = new Button();
b.label = 'openNewWindow';
addChild(b);
b.addEventListener(MouseEvent.MOUSE_DOWN, OpenPopUpWindow);
function OpenPopUpWindow(e:MouseEvent):void {
  var result:String = ;
  var url:URLRequest = new URLRequest("javascript:window.open('http://www.totusinfo.com','win','height=800,
           width=800,toolbar=yes,scrollbars=yes');void(0);");
  navigateToURL(url, "_self");
}
 

Why to use sharpness for textFields in Flash AS3 (Actionscript)

Posted by druva | as3, utils | Friday 27 February 2009 4:04 am
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

var labelText:String = 'This is brown fox';

function TextFieldExample() {
 configureLabel(numberText1, -400);
 configureLabel(numberText2, -300);
 configureLabel(numberText3, -200);
 configureLabel(numberText4, -100);
 configureLabel(numberText5, 100);
 configureLabel(numberText6, 200);
 configureLabel(numberText7, 300);
 configureLabel(numberText8, 400);
 configureLabel(numberText9, -100);
}

var _arial_str:String;
var myFont:Font = new Font1();
function configureLabel(targ, shrp:Number):void {
 targ.footer_number.autoSize = TextFieldAutoSize.LEFT;
 targ.footer_number.background = false;
 targ.footer_number.border = false;
 targ.footer_number.sharpness = shrp;

 var format:TextFormat = new TextFormat();
 format.font = myFont.fontName;
 format.color = 0xFFFFFF;
 format.size = 30;
 targ.footer_number.defaultTextFormat = format;
 targ.footer_number.text = labelText;
 targ.sharpnessValue.text = 'Sharpness ' + String(shrp);
}
TextFieldExample();
sslider.addEventListener(Event.CHANGE, on_sliderChange);
function on_sliderChange(e:Event){
 configureLabel(numberText9, sslider.value);
}
 

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

 

Remove White spaces from string in flash – Actionscript 3 (AS3)

Posted by druva | Flash, Flex, MXML, as3, utils | Monday 12 January 2009 4:06 am

This examples shows how to remove white spaces from the string


 public function removeSpaces(str:String):String {
 if (str == null) { return ''; }
 return str.replace(/\s+/g, '');
 }

This is the complete flex example


<?xml version="1.0" encoding="utf-8"?>
<mx:Application
 xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="absolute">
 <mx:Script>
 <![CDATA[

 public function removeSpaces(str:String):String {
 if (str == null) { return ''; }
 return str.replace(/\s+/g, '');
 }
 public function on_trim_button():void {
 reultText.text = removeSpaces(originalText.text);
 }
 ]]>
 </mx:Script>
 <mx:Button x="74" y="101" label="Trim Spaces" click="on_trim_button()"/>
 <mx:TextArea x="74" y="42" id="originalText" />
 <mx:TextArea x="74" y="157" id="reultText" />
 <mx:Label x="74" y="16" text="Enter Text" width="160"/>
 <mx:Label x="74" y="131" text="Enter Text" width="160"/>
</mx:Application>
 

How to Draw a Square with Flash Actionscript 3.0 – AS3

Posted by druva | Flash, as3, utils | Monday 5 January 2009 1:03 pm

simple Example to draw square using flash actionscript

this example show how to use lineStyle, drawRect, Shape

package druva {

import flash.display.*;

public class drawSquare extends Sprite {

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

}
}
}

 

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);

 }
 }
}
 
« Previous PageNext Page »