Abdulcode

Pages

Jul 26, 2010

Function parameters

Pass by Value
function passPrimitives(xParam:int, yParam:int):void
{
xParam++;
yParam++;
trace(xParam, yParam);
}

var xValue:int = 10;
var yValue:int = 15;

trace(xValue, yValue); // 10 15
passPrimitives(xValue, yValue); // 11 16
trace(xValue, yValue); // 10 15

Pass by Reference
function passByRef(objParam:Object):void
{
objParam.x++;
objParam.y++;
trace(objParam.x, objParam.y);
}

var objVar:Object = {x:10, y:15};

trace(objVar.x, objVar.y); // 10 15
passByRef(objVar); // 11 16
trace(objVar.x, objVar.y); // 11 16
The objParam parameter references the same object as the global objVar variable. As you can see from the trace statements in the example, changes to the x and y properties of the objParam object are reflected in the objVar object.

Jul 23, 2010

AS3 : Dynamic classes

A dynamic class defines an object that can be altered at run time by adding or changing properties and methods. A class that is not dynamic, such as the String class, is a sealed class. You cannot add properties or methods to a sealed class at run time.

You create dynamic classes by using the dynamic attribute when you declare a class. For example, the following code creates a dynamic class named "DynamicClass".

Code : /*Main.as*/
package
{
import flash.display.Sprite;

public class Main extends Sprite
{
public function DynamicClassCode()
{
var dClass:DynamicClass = new DynamicClass();

dClass.age = 25; // Dynamically add new variable.
// Dynamically add new Method.
dClass.getDetails = function():void
{
trace(dClass.nama);
trace(dClass.age);
}

dClass.getDetails(); // Method call
}
}
}

dynamic class DynamicClass
{
public var nama:String = "Abdul";
}

Jul 22, 2010

Flex: Custom Tooltip - IToolTip

While Creating the Tooltip the main thing is, the particular component/control's attribute toolTip=" " must contain space or any char's, but should not be empty or null.

Sample Main: /*Main.mxml*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical">

<mx:Script>
<![CDATA[
import com.abdul.TipComp;
import mx.events.ToolTipEvent;

private function callTootTip(e:ToolTipEvent):void
{
var touchedLabel:String = e.target.label;

var tc:TipComp = new TipComp();
tc.setText = touchedLabel; // pass value to the component.

e.toolTip = tc;
}
]]>
</mx:Script>

<mx:Button label="Tool Tip Button"
toolTip=" "
toolTipCreate="callTootTip(event)"/>
</mx:Application>


Here,
1. In the user define component we have to implement the IToolTip interface like this implements="mx.core.IToolTip".
2. The setText (it is a user define method for our convenience) method is used to get the value from the caller.
3. Image is used as a ToolTip.

Sample Component: /*TipComp.mxml*/
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
implements="mx.core.IToolTip"
horizontalAlign="center"
verticalAlign="middle">

<mx:Script>
<![CDATA[
import mx.core.IToolTip;

[Bindable]
private var value:String = "";

/* used to get value from the caller */
public function set setText(value:String):void
{
this.value = value;
}

public function set text(txt:String):void
{
}

public function get text():String
{
return "";
}
]]>
</mx:Script>

<mx:Label id="lab"
text="{value}"/>
<mx:Image x="87"
y="10"
height="280"
width="226"
source="@Embed(source='Earth_axis.jpg')"/>
</mx:VBox>