fadeOut a MovieClip in as2

Posted by Vineela | Uncategorized | Tuesday 21 October 2008 3:17 am

The below code shows how to fadeOut a MovieClip


function fadeOut (mc:MovieClip, speed:Number):Void  {
    mc.onEnterFrame = function() {
        if (mc._alpha>=0) {
            mc._alpha -= speed;
        } else {
            delete mc.onEnterFrame;
        }
    };
};

fadeOut(myMovieClipInstance, 5);

You can also declare the same as protoType


MovieClip.prototype.fadeOut = function(speed:Number):Void  {
    this.onEnterFrame = function() {
        if (this._alpha>=0) {
            this._alpha -= speed;
        } else {
            delete this.onEnterFrame;
        }
    };
};

myMovieClipInstance.clip_mc.fadeOut(5);
 

Representational State Transfer (REST)

Posted by druva | Flash, Flex, MXML, as3 | Monday 20 October 2008 1:41 am

Representational State Transfer(REST), This is a method that can identify by a URI.

IT supports HTTP methods GET, POST, PUT, DELETE, HEAD and OPTIONS.

It is possible to do everything that you can do with RPC web service with REST.

Problem with flash and REST is Flash support only GET and POST

Air Supports few more read this document URLRequest
for further information read this link NPAPI

 

calculate distance between two points in as2

Posted by Vineela | Uncategorized | Sunday 19 October 2008 3:10 am

The below code shows how to calculate distance between two points in as2


 private function distanceBetween(var x1:Number, var y1:Number, var x2:Number, var y2:Number):Number {
  var diffX = x2-x1;
  var diffY = y2-y1;
  return Math.sqrt((diffX*diffX)+(diffY*diffY));
 }
trace(distanceBetween(20,20,100,100));
 

spiral navigation menu

Posted by druva | Uncategorized | Saturday 18 October 2008 2:29 pm

This movie requires Flash Player 9

source

 

Flash Rotation2

Posted by druva | Flash, as3 | Friday 17 October 2008 8:00 am

This is another way of rotation related to my previous post

Rotation changes depending on the mousex position


rotator.addEventListener(MouseEvent.MOUSE_DOWN, initialize);
rotator.addEventListener(MouseEvent.MOUSE_MOVE, mouseMover);
rotator.addEventListener(MouseEvent.MOUSE_UP, deinitialize);

var dragging;
var actual_rotation;
var mouse_pos;

function initialize(evt:Event){
 mouse_ref = mouseX;
 dragging = true;
 actual_rotation = rotator.rotation;

}

function mouseMover(evt:Event){
 if(dragging){
 rotator.rotation = actual_rotation + (mouseX - mouse_pos)* 3;
 }

}

function deinitialize(evt:Event){
 dragging = false;
}

This movie requires Flash Player 9

 

Flash Webservices: Channel.Security.Error

Posted by druva | Flash, as3 | Thursday 16 October 2008 1:37 am

When Flex app retrieves data from a different server with httpservice.

It fails with the message:

Channel.Security.Error screenshot

The following unexpected error has occured:


 [FaultEvent fault=[RPC Fault faultString="Security error accessing url"
 faultCode="Channel.Security.Error"
 faultDetail="Destination: DefaultHTTPS"]
 messageId="8A12F18B-13A3-8D33-D013-5729A34FAC95"
 type="fault"
 bubbles=false cancelable=true eventPhase=2]

This is where crossdomain.xml come into picture.

you have to create a crossdomain.xml and host it on the data server domain root.

so flash player reads it first and then load the data request.


 <?xml version="1.0"?>
 <cross-domain-policy>
 <allow-http-request-headers-from domain="*"
 headers="*" secure="true"/>
 </cross-domain-policy>
 

Flash-Rotation

Posted by druva | Flash, as3, utils | Wednesday 15 October 2008 1:35 am

This shows how you can rotation a button around itself on clicking and moving the mouse.


rotator.addEventListener(MouseEvent.MOUSE_DOWN, initialize);
rotator.addEventListener(MouseEvent.MOUSE_MOVE, mouseMover);
rotator.addEventListener(MouseEvent.MOUSE_UP, deinitialize);

var dragging;
var actual_mouse_angle;
var actual_rotation;
var actual_x;

function initialize(evt:Event){
 dragging = true;
 actual_mouse_angle = Math.atan2(mouseY-rotator.y, mouseX-rotator.x) * 180/Math.PI;
 actual_rotation = rotator.rotation;
 actual_x = mouseX;
}

function mouseMover(evt:Event){
 if(dragging){
 curr_mouse_angle = Math.atan2(mouseY-rotator.y, mouseX-rotator.x) * 180/Math.PI;
 rotator.rotation = actual_rotation + curr_mouse_angle - actual_mouse_angle;
 }
}

function deinitialize(evt:Event){
 dragging = false;
}

download source code

This movie requires Flash Player 9

 

Flex Accordion Header Color

Posted by druva | Flex, MXML, as3, utils | Tuesday 14 October 2008 1:32 am

This examples shows how to control accordion header text color

here is the complete example in flex –


<?xml version="1.0" encoding="utf-8"?>
<mx:Application
 xmlns:mx="http://www.adobe.com/2006/mxml"
 width="600"
 height="600"
 >

 <mx:Script>
 <![CDATA[
 public function setColors():void {
 myAcc.getHeaderAt(0).setStyle('color', 0xFF0000);
 myAcc.getHeaderAt(1).setStyle('color', 0x00FF00);
 myAcc.getHeaderAt(2).setStyle('color', 0x0000FF);
 }
 ]]>
 </mx:Script>

 <mx:Accordion id="myAcc" width="300" height="300" creationComplete="setColors()">
 <mx:VBox label="Container 1">
 <mx:Text text="123456"/>
 </mx:VBox>

 <mx:VBox label="Container 2">
 <mx:Text text="123456890"/>
 </mx:VBox>

 <mx:VBox label="Container 3">
 <mx:Text text="123456890 123456"/>
 </mx:VBox>
 </mx:Accordion>
</mx:Application>
 

Flex HTTPService and PHP

Posted by druva | Flex, as3 | Monday 13 October 2008 1:29 am

This examples shows how to use HTTPService for communicating with php.


 <?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="fnCreationComplete()">
<mx:HTTPService id="httpserv"
url="http://localhost/test/httpserv.php"
result="diplayResult(event)"
fault="handleFault(event)"
method="POST"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
private function fnCreationComplete():void {
var Obj:URLVariables=new URLVariables();
Obj.username=2;
Obj.pass=5;
httpserv.send(Obj);
}
private function handleFault(event:FaultEvent):void{
Alert.show("faultString="+event.fault.faultString, "Error ID="+event.fault.errorID);
}

private function diplayResult(event:ResultEvent):void{
Alert.show(event.result.toString());
}
]]>
</mx:Script>
</mx:Application>

here is the Php code–


 echo 'User name is '.($_POST['username'].' and password is '.$_POST['pass']);
 

string-word counter for action script

Posted by Vineela | Uncategorized | Sunday 12 October 2008 3:04 am

function wordCounter(string:String):Number {
    var arr:Array = string.split(" ");
	var n:Number = 0;
	while(n < arr.length) {
		 if (arr[n] == "") {
            arr.splice(n,1);
        }
		n++;
	}
    return arr.length;
}
trace(wordCounter("This is totus flash action script blog"));
 
« Previous Page