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

 

How to use URLVariables() in Flash AS3?

Posted by druva | Flash, Flex, as3, utils | Monday 25 January 2010 10:26 pm

Using URLVariables in Flash or Flex we can send and receive data from server he is the example

This is the PHP Code nested in the server
Create a PHP file and place it in the server

<?php
 $email=$_POST['email'];
 $password=$_POST['password'];

echo "email=".$_POST['email']."&amp;password=".$password;
?>

Here is the code in Flash/Flex

//create URLRequest instace withe the target URL
var request:URLRequest = new URLRequest("http://www.example.com/data.php");

//create instance of the class
var variables:URLVariables = new URLVariables();

variables.email = druva.flash@gmail.com;
variables.password = 'dontexpectit';

//add the data to the URLRequest
request.data = variables;

//Choose a method as POST
request.method = URLRequestMethod.POST;

var loader:URLLoader = new URLLoader();
//Create EventListener
loader.addEventListener(Event.COMPLETE, handleComplete);

//send the request with URLLoader()
loader.load(request);

 function handleComplete(event:Event)  {
var loader:URLLoader = URLLoader(event.target);
var vars:URLVariables = new URLVariables(loader.data);

//Read data for the result
trace("vars.email: "+vars.email);
trace("vars.password: "+vars.password);
 }
 

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&gt;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

 

Image rotating in Y direction with tweener using flash actionscript

Posted by Vineela | Flash, as3, utils | Friday 6 November 2009 6:01 am

To see the effect please click on the below image


import caurina.transitions.Tweener;

var values:int=0;

heart.addEventListener(MouseEvent.MOUSE_DOWN,rotate);

function rotate(evt:MouseEvent):void
{
	values = values - 1;
	Tweener.addTween(heart,{rotationX:values*0,rotationY:values*180,time:1,transition:"easeInCubic"});
}

This movie requires Flash Player 9

 

Image rotating in X direction with tweener using flash actionscript

Posted by Vineela | Flash, as3, utils | Thursday 5 November 2009 5:58 am

To see the effect please click on the below image


import caurina.transitions.Tweener;

var values:int=0;

heart.addEventListener(MouseEvent.MOUSE_DOWN,rotate);

function rotate(evt:MouseEvent):void
{
	values = values - 1;
	Tweener.addTween(heart,{rotationX:values*180,rotationY:values*0,time:1,transition:"easeInCubic"});
}

This movie requires Flash Player 9

 

Image rotating in Y direction using flash actionscript

Posted by Vineela | Flash, as3, utils | Wednesday 4 November 2009 5:26 am

heart.addEventListener(Event.ENTER_FRAME,rotateY);

function rotateY(evt:Event):void
{
	evt.target.rotationY = evt.target.rotationY + 2;
}

This movie requires Flash Player 9

 

Image rotating in X direction using flash actionscript

Posted by Vineela | Flash, as3, utils | Tuesday 3 November 2009 1:19 am

heart.addEventListener(Event.ENTER_FRAME,rotateX);

function rotateX(evt:Event):void
{
	evt.target.rotationX = evt.target.rotationX + 2;
}

This movie requires Flash Player 9

 

editable and non-editable textinput using flash actionscript

Posted by Vineela | Flash, Flex, as3, utils | Sunday 14 December 2008 4:53 am
import fl.controls.CheckBox;
import fl.controls.TextInput;

var cB:CheckBox = new CheckBox();
cB.label = "Edit Text";
cB.addEventListener(Event.CHANGE, cB_edit);
cB.move(10, 5);
addChild(cB);

var tI:TextInput = new TextInput();
tI.editable = false;
tI.move(17, 30);
addChild(tI);

function cB_edit(evt:Event):void {
    tI.editable = cB.selected;
}
 

masked password in textArea with flash actionscript

Posted by Vineela | Flash, as3, utils | Friday 5 December 2008 5:05 am
import fl.controls.CheckBox;
import fl.controls.TextArea;

var cB:CheckBox = new CheckBox();
cB.label = "Display as Password";
cB.addEventListener(Event.CHANGE, cB_password);
cB.width = 200;
cB.move(10, 5);
addChild(cB);

var tA:TextArea = new TextArea();
tA.displayAsPassword = false;
tA.width = 125;
tA.move(15, 40);
addChild(tA);

function cB_password(evt:Event):void {
    tA.displayAsPassword = cB.selected;
}
 

disable Slider component using flash actionscript

Posted by Vineela | Uncategorized | Tuesday 2 December 2008 4:38 am
import fl.controls.Slider;
import fl.controls.CheckBox;
import flash.display.*;

var checkBox:CheckBox = new CheckBox();
checkBox.label = "enabled";
checkBox.addEventListener(Event.CHANGE, checkBox_action);
checkBox.move(20,5);
addChild(checkBox);

var slider:Slider = new Slider();
slider.enabled = false;
slider.move(30, 40);
addChild(slider);

function checkBox_action(evt:Event):void {
    slider.enabled = checkBox.selected;
}
 
Next Page »