Monday, September 24, 2012

3D in Flash




3D in Flash

Hi Friends I am Raghunath,

Today I want to discuss 3D in Flash. We will learn about how to make 3D environment  how to make primitives and how to load heavy, animated 3D models into Flash.

Following is the output we will get after completion of this project. 



Using Flare3D in FlashDevelop4.0


First we need to have know about flash player capabilities.

before and fp8 doesn't have 3d capabilities. Flash Player9 and above has render 3d capabilities. Flash Player 11 has special GUP acceleration.
Flash use many 3D engines. engines means it can be library file or swc(adobe's own zip format) file. some of these free and other has cost.
Following table has shown name of these and other information.

1) Alternativa3D
2) Away3D
3) Five3D
4) Flare3D
5) Papervision3D
6) Sandy
7) Yogurt3D


We will using Flare3D for import 3d model and to add interactivity to in it.

About Flare3D

Flare3D is very excellent for who want to make 3d flash game. There are lots of 3D flash libraries available for flash (Open Source and pay). E.g. Away3D, Papervision, Sandy3D and 

many more. But, they don’t have capabilities to handle 3D model properly,  means some of them can’t import model’s texture or animation.

Still, no worry. Flare3D is good for us.

But before going forth look through following points.

1) Plugin available for 3dsmax  - Flash doesn't read convesional 3d formats, e.g. 3ds, or collada. some of engines read it but Flare3d need own build format 'f3d'. and so they provide 

us plugin for 3dsmax2010.  It converts 3d max's model or animation into Flare3D format 'f3d'.  it's will readable for Flash with Flare 3D. We cab set animation lable or variable into 3dsmax and preview live.

2) It's require Flash Player11. It's  need to play in browser or FlashPlayer11. if you want to see in browser you have to need install flash-player's plugins and active-x versions.

3) Work need to be done in FlashDevelop or Flash Builder. and you can setup for Flash also.

4) 3D File format supported is obj, dae, and f3d format.


What we need to first.

download flare3d from here. we can get sample projects there. save zip which named 'flared3' extracted it we get 'flare3d_prerelease' project file which will open in 'FlashDevelop'. FD is open-source ActionScript Editor which is available here. after installation we can open this project file.

we 


















Tuesday, April 19, 2011

Welcome my Friends, I am Raghunath and here is my Flash Stuff.


Hi Friends, I am working in Flash Animation, ActionScript 2.0 & 3.0, Photoshop, Flex and FlashDevelop, GreenSock.

I am Seeking a challenging career in the field of Multimedia-Programming and also Designing to apply my knowledge, skill sets and innovative abilities towards the goal of an organization. I want to become well Flash professional to shape my career in flash, where my creativity is valuable.
My Great Web page
I also take freelance projects. If you want to make flash animation or programming and website. contact me.
Please see the website here. : raghunathsontakke@biz.ly or add me as friend on facebook-name is https://www.facebook.com/raghunathdsontakke
My Google Profile My Personal Website is here. raghunathsontakke.biz.ly

Tuesday, April 12, 2011

Create a Dynamic Bar Graph Generator Using XML + AS3


package
{

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import fl.transitions.Tween
import fl.transitions.easing.Strong

public class Graph extends Sprite
{

private var container:Sprite;
private var tf:TextFormat = new TextFormat();
private var totalBars:int;
private var urlLoader:URLLoader = new URLLoader();
private var xmlFile:XML;
private var tween:Tween;



public function Graph()
{
trace("constructor code");

tf.size = 12;
tf.color = 0x366666;
tf.font = "Helvetica"

createContainer();
loadXML();
}

private function createContainer():void
{
container = new Sprite();
container.graphics.lineStyle(1);
container.graphics.moveTo(30,30);
container.graphics.lineTo(30,360);
container.graphics.lineTo(480,360);
addChild(container);
}

private function loadXML(file:String="graph.xml"):void
{
//trace("loadXML()")
urlLoader.load(new URLRequest(file));
urlLoader.addEventListener(Event.COMPLETE, parseXML);
}
private function parseXML(e:Event)
{
xmlFile = new XML(e.target.data);
totalBars = xmlFile.children().length();
//trace(xmlFile +"\n"+totalBars);
createBars();
createNames()
}
private function createBars():void
{
for (var i:int=0; i<totalBars; i++)
{
var bar:Sprite = new Sprite();
bar.graphics.beginFill(xmlFile.children()[i].@color);
bar.graphics.drawRect(0,0,xmlFile.@width, xmlFile.children()[i].@value);
bar.graphics.endFill();
addChild(bar);

bar.x = 60 + (xmlFile.@width * i) + (10 * i);
bar.y = 340 - bar.height

tween  = new Tween(bar,"height",Strong.easeOut,0,bar.height,1,true)

var val:TextField = new TextField()
val.defaultTextFormat = tf;
addChild(val)
//val.defaultTextFormat(tf)
//val.defaultTextFormat(tf)
val.text = xmlFile.children()[i].@value
val.x = 60 + (xmlFile.@width * i) + (10 * i);
val.y = 190 - bar.height


}

}

private function createNames():void{
for(var i:int = 0 ; i<totalBars; i++){
var color:Sprite = new Sprite()
color.graphics.beginFill(xmlFile.children()[i].@color)
color.graphics.drawRect(0,0,10,10)
color.graphics.endFill()
addChild(color)
color.x = 400
color.y = 60 + (30* i)

var names:TextField = new TextField()
names.defaultTextFormat = tf
names.text = xmlFile.children()[i].@name
names.x = 420
names.y = 60 + (30 * i)
addChild(names)


}
}

}

}
//graph.xml file content
/*
<graphs width="50">
<graph name="Red" value="30" color="0xFF0000"/>
<graph name="Green" value="80" color="0x00FF00"/>
<graph name="Blue" value="50" color="0x0000FF"/>
</graphs>
*/

Friday, February 18, 2011

Text Scrolller in AS2


// SET Y INITIAL POSITION
targY = 0;
// SET THE INITIAL POSIZION OF THE SCROLLER X
//dragger._x = mask._width;
// DRAG FUNCTION
scroller.onPress = function() {
startDrag(this, false, this._x, 0, this._x, mask._height-this._height);
};
// END DRAG
scroller.onRelease = scroller.onReleaseOutside=function () {
stopDrag();
};
// MANAGE THE MOVEMENTS THAT CONTENT SHOULD DO
content.onEnterFrame = function() {
// CALCULATE THE MOVEMENT THE CONTENT WILL DO
movement = (this._height-(mask._height/1.3))/(mask._height-scroller._height);
// RE REST THE Y POSITION
targY = -scroller._y*movement;
// INCREASE OR DECREASE THE NUMBER "7" TO MOVE THE CONTENT FASTER OR SLOWER
this._y -= (this._y-targY)/7;
};

stop();

Monday, January 10, 2011

Displaying Images Using BitmapData

import flash.display.BitmapData;
import flash.filters.DropShadowFilter;
import mx.controls.Button;

var nextIMG:Number = 0;
var image:Array;
var index = 0;
var buttonXPos:Number;
var buttonYPos:Number;



xml.load("xmlName.xml");*/

// give following array element as a linkage name to imported images in library or set linkage name as a array element as a string.

image = ["sunflw", "chr", "diw1", "diw2", "diw3", "flw", "lady", "wallp", "win"];

var mc:MovieClip = this.createEmptyMovieClip("mc", 1);
var drop:DropShadowFilter = new DropShadowFilter();
mc.filters = [drop];
mc._y = 10;

var bmpdata:BitmapData = BitmapData.loadBitmap(image[index]);
beginBitmapFill();

this.createClassObject(Button,"back_btn",11,{_width:40, label:"Back"});
this.createClassObject(Button,"next_btn",12,{_width:40, label:"Next"});

buttonXPos = (Stage.width / 2) - (this._width);
buttonYPos = 200;

//trace(buttonXPos);

back_btn._x = buttonXPos + 100;
back_btn._y = buttonYPos;

next_btn._x = buttonXPos + 260;
next_btn._y = buttonYPos;


function beginBitmapFill()
{
if (bmpdata.width <= 250)
{
mc.beginBitmapFill(bmpdata,null,true);
mc.lineStyle(2,0xFF6600);
mc.lineTo(200,0);
mc.lineTo(200,160);
mc.lineTo(0,160);
mc.lineTo(0,0);

}
else if (bmpdata.width >= 200)
{
mc.beginBitmapFill(bmpdata,null,true);
mc.lineStyle(2,0xFF6600);
mc.lineTo(bmpdata.width,0);
mc.lineTo(bmpdata.width,bmpdata.height);
mc.lineTo(0,bmpdata.height);
mc.lineTo(0,0);

}
}

next_btn.addEventListener("click",nextImageHandler);
function nextImageHandler()
{
if (index < (image.length - 1))
{
index++;
laodImage();
}
else if (index == (image.length - 1))
{
next_btn._visible = false;
back_btn._visible = true;
prevImageHandler();
}
}

mc.onEnterFrame = function()
{
//SET POSITION OF MOVIECLIP AND BUTTONS
mc._x = ((Stage.width / 2) - (mc._width / 2));

if (index == (image.length - 1))
{
next_btn._visible = false;
back_btn._visible = true;
back_btn.addEventListener("click",prevImageHandler);
}
else if (index == 0)
{
prevImageHandler();
}
};

function prevImageHandler()
{
if (index == 0)
{
back_btn._visible = false;
next_btn._visible = true;
}
else
{
index--;
laodImage();
}
}
function laodImage()
{
bmpdata = BitmapData.loadBitmap(image[index]);
mc.clear();
beginBitmapFill();
}

next_btn.swapDepths(1000);

Wednesday, December 29, 2010

Simple Hit Game

import fl.transitions.Tween;
import fl.transitions.easing.None;
import fl.transitions.easing.Bounce;
import fl.transitions.TweenEvent;
import flash.utils.Timer;

var score:Number=0;
score_txt.text="Score : "+String(score);
win_mc.alpha=0;
function mouseMoveListener(evt:MouseEvent):void {
    if (evt.currentTarget.mouseY<=(stage.stageHeight-tankar_mc.height)) {
        tankar_mc.y=evt.currentTarget.mouseY;
    }
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
stage.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);


tankar_mc.fire_mc.alpha=100;
function clickHandler(evt:MouseEvent):void {
    var myTween:Tween=new Tween(tankar_mc.fire_mc,"x",None.easeNone,0,(stage.stageWidth),1,true);
    myTween.addEventListener(TweenEvent.MOTION_FINISH, finishFireHandler);
}
var repeat:Number=30;
var delay:Number=1000;
var t:Timer=new Timer(delay,repeat);
t.start();
t.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
t.addEventListener(TimerEvent.TIMER, timerHandler);

function timerHandler(e:TimerEvent):void {
    repeat--;
    statusTextField.text = ((delay * repeat) / 1000) + " seconds left.";
}

function timerComplete(evt:TimerEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
    stage.removeEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
    myTween.removeEventListener(TweenEvent.MOTION_FINISH, motionFinishHandler);
    score_txt.text="Times Up";
    tankar_mc.fire_mc.alpha=0;
}

function finishFireHandler(evt:TweenEvent):void {

    var fire:MovieClip=tankar_mc.fire_mc as MovieClip;
    if (tankar_mc.fire_mc.hitTestObject(target_mc)) {
        tankar_mc.fire_mc.x=0;
        tankar_mc.fire_mc.alpha=100;
        trace("Hit");
        score++;
        if (score==10) {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
            stage.removeEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
            myTween.removeEventListener(TweenEvent.MOTION_FINISH, motionFinishHandler);

            var winTween:Tween=new Tween(win_mc,"alpha",None.easeInOut,0,100,1,true);
            t.stop();
            stage.removeEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
        }
        score_txt.text="Score : "+String(score);
    } else {

    }
}

function motionFinishHandler(evt:TweenEvent):void {
    evt.currentTarget.yoyo();
}
var myTween:Tween=new Tween(target_mc,"y",None.easeNone,0,(stage.stageHeight-target_mc.height),3,true);
myTween.addEventListener(TweenEvent.MOTION_FINISH, motionFinishHandler);