Flash actionscript 3.0: April 2009

Load the images from web using xml and AS3.0

2

Posted by Sankar.G | Posted in | Posted on 2:16 PM

This script is used to load the images from web using XML and display
it on the stage script is in the Below Link downLoad it and use it

XMLimages.zip

Below script i used to create a plane and bitfilematerial effect in papervision3D

2

Posted by Sankar.G | Posted in | Posted on 5:15 PM

copy this below code and save it as a "four.as" and give link to the file from flash and dont forget

the download the papervision.zip file from the previous Blog and kept org & com & fl & this as file and

fla file in the same folder and run the file it will work


package
{
import flash.display.ActionScriptVersion;
import flash.display.Scene;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.core.utils.InteractiveSceneManager;
import org.papervision3d.events.FileLoadEvent;

import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.objects.primitives.Plane;

public class four extends Sprite
{
private var view:Viewport3D;
private var camera:Camera3D;
private var light:PointLight3D;
private var plane:Plane;
private var render:BasicRenderEngine;
private var scene:Scene3D;
private var man:InteractiveSceneManager;
private var universe:DisplayObject3D;
private var mat:BitmapFileMaterial;

public function four():void
{
init();
}
private function init():void
{
view = new Viewport3D(0, 0, true);
view.opaqueBackground = 0x000000;
addChild(view);
man = new InteractiveSceneManager(view);

camera = new Camera3D();
camera.z = -2000;
camera.zoom = 2;

light = new PointLight3D(false);
scene = new Scene3D();

render = new BasicRenderEngine();

universe = new DisplayObject3D();
mat = new BitmapFileMaterial();
mat.texture ="http://www.flowerstodubai.com/images/Mixed%20Flowers%20and%20a%20Bear.jpg"
mat.interactive = true;
mat.smooth = true;
mat.tiled = true;
mat.addEventListener(FileLoadEvent.LOAD_COMPLETE, call);
function call(event:FileLoadEvent):void
{
plane = new Plane(mat, 3000, 3000, 8);
universe.addChild(plane);
scene.addChild(universe);

addEventListener(Event.ENTER_FRAME, fun);
man.container.addEventListener(MouseEvent.CLICK, click);
}
}
private function click(event:MouseEvent):void
{
plane.rotationZ += 10;
}
private function fun(event:Event):void
{
render.renderScene(scene, camera, view);
}
}

}

Simple Example of a PaperVision 3d in AS3

0

Posted by Sankar.G | Posted in | Posted on 12:16 PM

First Download the PaperVision3d Pack

papervision.zip

extract the zip file
And Create a ActionScript File and Name it as "two" save the file in the same folder
And put this script in class folder

package
{
import flash.display.ActionScriptVersion;
import flash.display.Scene;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

import org.papervision3d.materials.shadematerials.GouraudMaterial;
import org.papervision3d.objects.primitives.Cone;

public class two extends Sprite
{
private var scene:Scene3D;
private var viewport:Viewport3D;
private var camere:Camera3D;
private var light:PointLight3D;
private var renderer:BasicRenderEngine;
private var universe:DisplayObject3D;

private var gouraudCone:Cone;
private var gouraudMat:GouraudMaterial;

public function two()
{
init();
}
private function init():void
{
viewport = new Viewport3D(0, 0, true);
viewport.opaqueBackground = 0;
addChild(viewport);

renderer = new BasicRenderEngine();

camere = new Camera3D();
camere.z = -2000;
camere.zoom = 2;

light = new PointLight3D(true);
scene = new Scene3D();

gouraudMat = new GouraudMaterial(light, 0,0x00ff00);

gouraudCone = new Cone(gouraudMat,800, 800, 10,10);
gouraudCone.x = 0;



universe = new DisplayObject3D();
universe.addChild(gouraudCone);
scene.addChild(universe);

addEventListener(Event.ENTER_FRAME, render);
}
private function render(event:Event):void
{
universe.rotationX += 10;
universe.rotationY += 10;
universe.rotationZ += 10;
renderer.renderScene(scene, camere,viewport);
}
}

}

Create a Empty flash File and give link to the class file name in the Docoument Class text Box and run

the flash file

Result:

Cone.swf

Draw a Draggable triangle using Actionscript 3.0

0

Posted by Sankar.G | Posted in | Posted on 3:41 PM

you can draw a triangle with out any design using script copy the below script and past it in flash first Frame and run the file make a three click on the stage and drag the points


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

var p1:Sprite=new Sprite();
p1.addEventListener(MouseEvent.MOUSE_DOWN,drag1);
addChild(p1);

var p2:Sprite=new Sprite();
p2.addEventListener(MouseEvent.MOUSE_DOWN,drag2);
addChild(p2)

var p3:Sprite=new Sprite();
p3.addEventListener(MouseEvent.MOUSE_DOWN,drag3);
addChild(p3)

stage.addEventListener(MouseEvent.MOUSE_MOVE,moves);
stage.addEventListener(MouseEvent.MOUSE_UP,all);

stage.addEventListener(MouseEvent.CLICK,fun);
var boo:Number=0;
function moves(event:MouseEvent):void
{
if(boo==3)
{
l1.graphics.clear();
drawLine();
}
}
function fun(event:MouseEvent):void
{
if(boo==0)
{
p1.graphics.lineStyle(1,0x00ff00);
p1.graphics.beginFill(0x00ff00);
p1.graphics.drawCircle(0,0,5);
p3.graphics.endFill();
p1.filters=[new DropShadowFilter()];
p1.x=mouseX;
p1.y=mouseY;
boo=1
}
else if(boo==1)
{
p2.graphics.lineStyle(1,0x00ff00);
p2.graphics.beginFill(0x00ff00);
p2.graphics.drawCircle(0,0,5);
p3.graphics.endFill();
p2.filters=[new DropShadowFilter()];
p2.x=mouseX;
p2.y=mouseY;
boo=2;
}
else if(boo==2)
{
p3.graphics.lineStyle(1,0x00ff00);
p3.graphics.beginFill(0x00ff00);
p3.graphics.drawCircle(0,0,5);
p3.graphics.endFill();
p3.filters=[new DropShadowFilter()];
p3.x=mouseX;
p3.y=mouseY;
boo=3;
drawLine();
}

}
function drawLine():void
{
l1.graphics.lineStyle(1,0xffff00);
l1.graphics.moveTo(p2.x,p2.y);
l1.graphics.lineTo(p3.x,p3.y);
l1.graphics.lineTo(p1.x,p1.y);
l1.graphics.lineTo(p2.x,p2.y);
l1.filters=[new DropShadowFilter()];
l1.graphics.endFill();
}
function drag1(event:MouseEvent):void
{
if(boo==3)
{
event.currentTarget.startDrag();
}
}
function drag2(event:MouseEvent):void
{
if(boo==3)
{
event.currentTarget.startDrag();
}
}
function drag3(event:MouseEvent):void
{
if(boo==3)
{
event.currentTarget.startDrag();
}
}
function all(event:MouseEvent):void
{
stopDrag();
}

Examples:
triangle.swf

Generating random Numbers with out repetation of the previous number in AS 3.0

0

Posted by Sankar.G | Posted in | Posted on 9:55 AM

var i:Number;
var a:Array=new Array("");
var b:Array=new Array("");
var c:Array=new Array("");


main();
function main()
{
for (i=1; i<
11; i++) {
a[i]=i;
}
for (i=1; i<
11; i++) {
var r:Number=a.length-1;
b[i]=Math.floor(Math.random()*r+1);
c[i]=a.splice(b[i],1);
}
for(i=1;i<
11;i++)
{
trace("n:"+c[i]);
}
}

pre Loader in AS 3 .0

0

Posted by Sankar.G | Posted in | Posted on 4:26 PM

var percentage:Number=0;
stage.addEventListener(Event.ENTER_FRAME,BeeMoving);
function BeeMoving(event:Event):void
{
var nLoadedBytes:Number = loaderInfo.bytesLoaded;
var nTotalBytes:Number = loaderInfo.bytesTotal;
percentage= Math.round(nLoadedBytes / nTotalBytes * 100);
BitsLoaded.text = nLoadedBytes+"kbs /"+nTotalBytes+"kbs";
if (nLoadedBytes==nTotalBytes) {
stage.removeEventListener(Event.ENTER_FRAME,BeeMoving);
gotoAndStop(2);
}
}

How to put 'U'shape Curve in AS 3.0

0

Posted by Sankar.G | Posted in | Posted on 5:28 PM

var angle:Number=0.05;
var radian:Number=0;
b1_btn.addEventListener(MouseEvent.CLICK,fun);
function fun(event:MouseEvent):void
{
ball_mc.y=351.9;
ball_mc.x=250;
addEventListener(Event.ENTER_FRAME,one);
function one(event:Event):void
{
angle+=0.05;
radian=Math.sin(angle)*3;
ball_mc.y=(351.9)-radian*180/Math.PI;
ball_mc.x+=2;
if(ball_mc.y>352.9)
{
removeEventListener(Event.ENTER_FRAME,one);
}
}
}

Create 2 MovieClip and Name it as b1_btn & ball_mc
and put this script and click the b1_btn button

Multiple KeyBoard Event in AS 3.0

2

Posted by Sankar.G | Posted in | Posted on 5:13 PM

var isKeyOne:Boolean = false;
var isKeyTwo:Boolean = false

stage.addEventListener(Event.ENTER_FRAME, checkTrue);

function checkTrue(event:Event):void
{
if(isKeyOne)
{
test.x--;
}
if(isKeyTwo)
{
test.y--;
}
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, makeTrue);
stage.addEventListener(KeyboardEvent.KEY_UP, makeFalse);

function makeTrue(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.LEFT)
{
isKeyOne = true;
}
if(event.keyCode == Keyboard.UP)
{
isKeyTwo = true;
}
}

function makeFalse(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.LEFT)
{
isKeyOne = false;
}
if(event.keyCode == Keyboard.UP)
{
isKeyTwo = false;
}
}
Create one MovieClip and Name it as test and Put this Script for Multiple Keyboard Handling

How to do the start Drag the APE Objects Dynamically

0

Posted by Sankar.G | Posted in | Posted on 6:44 PM

package
{
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
import org.cove.ape.*;

public class Test extends Sprite
{
private var wp:WheelParticle;
private var array:Array=new Array("");
private var i:Number;
public function Test():void
{
stage.frameRate = 20;
addEventListener(Event.ENTER_FRAME, run);
APEngine.init(2/4);
APEngine.container = this;
var defaultGroup:Group = new Group();
defaultGroup.collideInternal = true;
APEngine.addMasslessForce(new Vector(0,2));

var rp1:RectangleParticle=new RectangleParticle(490,300,200,10,-0.52,true);
defaultGroup.addParticle(rp1);
rp1.setFill(0xff0000);
rp1.setLine(0,0x666666,1);
rp1.sprite.name="rp1";
array.push(rp1);

var rp2:RectangleParticle=new RectangleParticle(430,450,200,10,0,true);
defaultGroup.addParticle(rp2);
rp2.setFill(0xff0000);
rp2.setLine(0,0x666666,1);
rp2.sprite.name="rp2";
array.push(rp2);

var rp3:RectangleParticle = new RectangleParticle(250,300,200,10,0.52,true);
defaultGroup.addParticle(rp3);
rp3.setFill(0x666666);
rp3.setLine(0, 0xff0000, 1);
rp3.sprite.name="rp3";
array.push(rp3);

for(i=1;i< 4;i++) { array[i].sprite.addEventListener(MouseEvent.MOUSE_DOWN,one); array[i].sprite.addEventListener(MouseEvent.MOUSE_UP,two); } function one(e1:MouseEvent):void { removeEventListener(Event.ENTER_FRAME,run); e1.target.startDrag(); } function two(e2:MouseEvent):void { array[e2.target.name.substr(2)].px=mouseX; array[e2.target.name.substr(2)].py=mouseY; stopDrag(); addEventListener(Event.ENTER_FRAME, run); } function run(evt:Event):void { APEngine.step(); APEngine.paint(); } } } } Example: APE with Dragable.swf

How to create rectangles & circles use APE & bounce effects

0

Posted by Sankar.G | Posted in | Posted on 4:31 PM

package {
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
import org.cove.ape.*;

public class Test extends Sprite
{
private var wp:WheelParticle;
public function Test():void
{
stage.frameRate = 20;
addEventListener(Event.ENTER_FRAME, run);
APEngine.init(2/4);
APEngine.container = this;
var defaultGroup:Group = new Group();
defaultGroup.collideInternal = true;
APEngine.addMasslessForce(new Vector(0,2));

var rp:RectangleParticle = new RectangleParticle(250,300,200,10,0.52,true);
defaultGroup.addParticle(rp);
rp.setFill(0x666666);
rp.setLine(0, 0xff0000, 1);

var rp1:RectangleParticle=new RectangleParticle(490,300,200,10,-0.52,true);
defaultGroup.addParticle(rp1);
rp1.setFill(0xff0000);
rp1.setLine(0,0x666666,1);

var rp2:RectangleParticle=new RectangleParticle(430,450,200,10,0,true);
defaultGroup.addParticle(rp2);
rp2.setFill(0xff0000);
rp2.setLine(0,0x666666,1);

wp = new WheelParticle(280,10,25,false,10,0.3,0.1,1);
defaultGroup.addParticle(wp);
wp.setFill(0xff0000);
wp.setLine(0,0xff0000,0);

wp.sprite.addEventListener(MouseEvent.MOUSE_DOWN,down);

wp.sprite.addEventListener(MouseEvent.MOUSE_UP,up);

APEngine.addGroup(defaultGroup);

function down(d1:Event):void
{
removeEventListener(Event.ENTER_FRAME,run);
wp.sprite.startDrag();
}
function up(d2:Event):void
{
wp.px=wp.sprite.x;
wp.py=wp.sprite.y;
stopDrag();
addEventListener(Event.ENTER_FRAME, run);
}
function run(evt:Event):void
{
APEngine.step();
APEngine.paint();
}

}


}
}

Examples:

APE with out Drag.swf