Pages

Friday, November 5, 2010

String Convert to MovieClip in ActionScript3.0

Do you want source file...

Click here...

StringToMC.zip

Card Flip in Action Script3.0




Example:


card_mc.addEventListener(MouseEvent.CLICK,cli);
function cli(event:MouseEvent)
{
if(card_mc.currentFrame==1)
startFlip(2) 
else
startFlip(1)
}


var flipStep:uint;
var isFlipping:Boolean = false;
var flipToFrame:uint;
/** begin the flip, remember which frame to jump to **/
function startFlip(flipToWhichFrame:uint) 
{
isFlipping = true;
flipStep = 10;
flipToFrame = flipToWhichFrame;
card_mc.addEventListener(Event.ENTER_FRAME, flip);
}
/** take 10 steps to flip **/
function flip(event:Event)
{
flipStep--; // next step
if (flipStep > 5)
{ // first half of flip
card_mc.scaleX = .2*(flipStep-6);

else 
{ /** second half of flip **/
card_mc.scaleX = .2*(5-flipStep);
}
/** when it is the middle of the flip, go to new frame **/
if (flipStep == 5)
{
card_mc.gotoAndStop(flipToFrame);
}
/** at the end of the flip, stop the animation **/
if (flipStep == 0)
{
card_mc.removeEventListener(Event.ENTER_FRAME, flip);
}
}


...CHeeRS...






SourceFile

Monday, September 13, 2010

Fetch XML data using AS3

Example source file for fetch xml data using as3....

XML:
XML:



<
Question
>
<
Answer
>
<
Question_Data heading= "what is your Name" ans= "kumaresh"
/
>
<
Question_Data heading= "what is you father Name" ans= "rengan"
/
>
<
Question_Data heading= "What are you doing" ans= "playing"
/
>
<
/
Answer
>
<
/
Question
>



As3:


var externalXML:XML=new XML;
var loader:URLLoader=new URLLoader();
var urlrequest:URLRequest=new URLRequest("question.xml");
loader.load(urlrequest);
loader.addEventListener(Event.COMPLETE,one);
var rows:Number;
var headingArray:Array=new Array();
var ansArray:Array=new Array();
var changeQue:Number=0;

function one(e1:Event):void
{
externalXML=new XML(loader.data);
rows=externalXML.Answer.Question_Data.length();
trace(rows);

for(var i:uint;i
<
rows;i++)
{
headingArray.push(externalXML.Answer.Question_Data[i].@heading); ansArray.push(externalXML.Answer.Question_Data[i].@ans);
}
display();
}
function display():void
{
heading.text=headingArray[changeQue]; ans.text=ansArray[changeQue];
}
arr1_btn.addEventListener(MouseEvent.CLICK,nextQue); arr2_btn.addEventListener(MouseEvent.CLICK,prevQue);
function nextQue(e2:MouseEvent):void
{
if(changeQue
<
(headingArray.length-1))
{
changeQue++;
display();
}
}
function prevQue(e3:MouseEvent):void
{
if(changeQue
<
headingArray.length&&changeQue
>
0)
{
changeQue--;
display();
}

}





Do you want down load this source file...


xmlFetch.zip

Saturday, August 14, 2010

Create a custom scroll bar in as3

Step 1 - Creating Our Text Fields


Open up the Starter File, go to the Actions Layer and press F9 to open up our Actions Panel. We need to create a Text Field and Format the text inside it, so we declare our variables for the Text Field and Text Format, and then give them some basic properties.


var myText:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();
myFormat.font = "Arial";
myFormat.color = 0×333333;
myFormat.size = 24;
addChild(myText);
myText.text = "This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!This is the Flash Essential custom scrollbar tutorial!!!";
myText.setTextFormat(myFormat);
myText.wordWrap = true;
myText.multiline = true;
myText.setTextFormat(myFormat);
myText.x = 100;
myText.y = 100;
myText.width = 300;
myText.height = 200;

Step 2 - Adding Our Mouse Events



Now we add some Mouse Events to our movie clips on the stage. Inside the functions we give our myText text field a scrollV method which means it's scrolling vertically, we then add some math so it reduces the scroll value by one each time its clicked. We do the same for the scrollDown_mc except we use += which adds one to the scroll value every time it's clicked.



scrollUP_mc.addEventListener(MouseEvent.CLICK, upScroll);
function upScroll(event:MouseEvent):void
{
trace(myText.scrollV);
myText.scrollV -= 1;
}
scrollDown_mc.addEventListener(MouseEvent.CLICK, downScroll);
function downScroll(event:MouseEvent):void
{
trace(myText.scrollV);
myText.scrollV += 1;
}

Step 3 - Controlling The Slider



First we'll add our mouse events, you'll notice we add our dropSlider to the stage instead of our slider_mc. This is to stop it scrolling once you have clicked away from the scroll bar.



slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragSlider);
stage.addEventListener(MouseEvent.MOUSE_UP, dropSlider);
var bounds:Rectangle = new Rectangle(slider_mc.x, slider_mc.y,0,70);
var dragging:Boolean = false;
function dragSlider(event:MouseEvent):void
{
slider_mc.startDrag(false,bounds);
dragging = true;
}
function dropSlider(event:MouseEvent):void
{
slider_mc.stopDrag();
dragging = false;
}
function checkSlider(event:Event):void
{
//if(dragging){trace("scroll");}
myText.scrollV = Math.round ((slider_mc.y - bounds.y)* myText.maxScrollV/70)
}
stage.addEventListener(Event.ENTER_FRAME, checkSlider);
function textScrolled(event:Event):void
{
slider_mc.y = bounds.y + (myText.scrollV * 70/myText.maxScrollV);
}
myText.addEventListener(Event.SCROLL, textScrolled);