Archive for the ‘Flex (RIA)’ Category

Remove All Children – Important Classes for games in AS 3.0

December 22nd, 2011 by aabhaanjan

images

[xml]
package
{

import flash.display.MovieClip;
/**
* …
* @description : This Class can be used when you need to remove all the childern of a parent movieClip.
* @author Aava Rani
*/
public class RemoveAllChildClass extends MovieClip
{

public function RemoveAllChildClass():void
{
trace(‘ Constructor called ‘);
}

public function removeAllChild(__parent:MovieClip):void {
if(__parent.numChildren!=0){
var __i:int = __parent.numChildren;
while(__i — )
{
__parent.removeChildAt( __i );
}
}
}

}

}
[/xml]

Remove movieclips from Array- Important Classes for games in AS 3.0

December 22nd, 2011 by aabhaanjan

images

[xml]
package
{

import flash.display.MovieClip;
/**
* …
* @description : This Class can be used when you need to remove all movieclips from its stored array.
* @author Aava Rani
*/
public class RemoveMovieClipsFromArrayClass extends MovieClip
{

public function RemoveMovieClipsFromArrayClass():void
{
trace(‘ Constructor called ‘);
}

public function removeAllMovieClipsFromArray(__clipArray:Array):void {
for (var __i:int = __clipArray.length – 1; __i >= 0 ; __i– ) {
removeChild(__clipArray[__i])
__clipArray.splice(__i, 1);
}
}

}

}
[/xml]

Depth Sorting of objects – Important Classes for games in AS 3.0

December 22nd, 2011 by aabhaanjan

images
[xml]
package
{
/**
* …
* @description : This Class can be used when you need to adjust depth of objects according to their heights.
* @author Aava Rani
*/

public class DepthSortingClass extends MovieClip
{
private var _parent:Object
public function DepthSortingClass()
{
super();
}

public function setSortingParent(__parent:Object):void {
_parent = __parent
}

public function sortDisplayList():void {
var len:uint = _parent.numChildren;
var i, j;
for ( i = 0; i < len - 1; i++ ) for (j = i + 1; j < len; j++) if ( _parent.getChildAt(i).y > _parent.getChildAt(j).y )
_parent.swapChildrenAt( i, j );

}

}

}

[/xml]

Loading SWFs in AIR- Important Classes for games in AS 3.0

December 22nd, 2011 by aabhaanjan

images

[xml]
package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;

/**
* …
* @description : This class is for loading SWFs in AIR for Mobile app etc.
* @author Aava Rani
*/
public class SWFLoader extends MovieClip
{
private var loader:Loader;
public function SWFLoader():void {
initLoader(‘test.swf’)
}

private function initLoader(__path:String):void {
loader = new Loader();
var appDomain:ApplicationDomain = new ApplicationDomain();
var context:LoaderContext = new LoaderContext(false, appDomain);
loader.load(new URLRequest(__path), context);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
}
private function loaded(event:Event):void
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loaded);
addChild(loader.content);
}

}
}
[/xml]

New things in Flash Builder 4.6

December 15th, 2011 by aabhaanjan

The Flex 4.6 SDK has a number of new features :
1. Support for the latest Flash Player 11 and AIR 3 runtimes.
2. Most important is a new set of Spark components for mobile applications.
3. Performance boost.
New things in Flash Builder 4.6
New Adobe AIR and Flash Player support
The most important features for the AIR and Player are :

a) AIR Native Extensions
It provides the ability to complement AIR application with native code. Which gives a wide range of options to create different applications.

b) Captive runtime

Another powerful new feature is the ability to embed the AIR 3 runtime in the final application. Which is called as Captive runtime.

New tools for mobile development
Unit testing mobile applications
It is now supporting the popular open-source FlexUnit framework for mobile projects.

Monitoring network activity for mobile applications
Using Flash Builder 4.6’s built-in network monitor feature we can see all the data being sent and received in the network during our test.

Flex 4.5 and AmfPhp connection and Data transfer

November 16th, 2011 by aabhaanjan

1

Lets see the other way of data transfer between external environment and the Flex using AMFPHP. Important points regarding AmfPhp ?

1. AMF stands for Action Message Format.

2. It is a binary file that is used to represent a serialized ActionScript object.

3. It was designed to serialize and deserialize quickly.

4. AMF 3 for ActionScript 3 and AMF 0 is for (AS1 & AS2).

5. AMF 3 supports sending int and uint objects.

6. AMFPHP automatically converts ActionScript data types to PHP data types.

Lets have an example amfPhp and Flex 4.5 connection and data exchange between them.
Step 1 : Install AmfPhp in your wamp server :

amfphp_in_root_directory_www

Step 2 : If installed properly check the gateway.php . It should look like this :

amfphp_gateway_look

Step 3 : Check the browser . It should look like this :

amfphp_in_browser_look

Step 4 : Write a class for php. Here I am writting a dummy data as return which is containing Employee detail.

[xml]

fname = “Aava”;

$emp->lname = “Anjan”;

$emp->age = 28;

return $emp;

}

}

?>

[/xml]

One more class is refrencing the employee. Further we will expand it in our next example .

[xml]

[/xml]
Step 4 : Check the browser and Click on ‘call’ button you will get result like this :

result_on_call

Step 5 : Now Create a new Flex Project where we will see the employee detail by connecting
with AmfPhp . Here are the codes :

[xml]

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:s=”library://ns.adobe.com/flex/spark”
xmlns:mx=”library://ns.adobe.com/flex/mx” minWidth=”955″ minHeight=”600″>
<fx:Declarations>
<!– Place non-visual elements (e.g., services, value objects) here –>
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.RemotingServiceManager;
import flash.events.MouseEvent;
private var _rc:RemotingServiceManager = new RemotingServiceManager()
protected function search_btn_clickHandler(event:MouseEvent):void{
_rc.getEmployeeDetail();
}
]]>
</fx:Script>
<s:Button id=”search_btn” x=”158″ y=”141″ width=”189″ height=”34″ label=”Click to Get Employee Detail”
click=”search_btn_clickHandler(event)”/>
<s:Label x=”150″ y=”95″ color=”#570404″ fontSize=”17″ text=”Example of Flex and AmfPhp”/>
</s:Application>

[/xml]

Step 6 : Run and Click on the Search button . It will show you result :

flex_result

Tags: , , , , , , , , , , , , , , ,

Flex XML socket connections

November 15th, 2011 by aabhaanjan

Binary Socket Server flex and Java

Before the example I would like give you a brief about XML connections :

XML socket connections vs binary socket connections:
1. An XMLsocket lets create a server connection that remains open until explicitly closed.
2. No need to having to continually open new server connections.
3. No need to explicitly request for sending  data.
The protocol used by the XMLSocket class are :
* XML messages are sent over a full-duplex TCP/IP stream socket connection.
* Each XML message is a complete XML document, terminated by a zero (0) byte.
* An unlimited number of XML messages can be sent and received over a single XMLSocket connection.
XMLSocket has no HTTP tunneling capability.

XML socket connections vs binary socket connections:

1. An XMLsocket lets create a server connection that remains open until explicitly closed.

2. No need to having to continually open new server connections.

3. No need to explicitly request for sending  data.

The protocol used by the XMLSocket class are :

* XML messages are sent over a full-duplex TCP/IP stream socket connection.

* Each XML message is a complete XML document, terminated by a zero (0) byte.

* An unlimited number of XML messages can be sent and received over a single XMLSocket connection.

Note : XMLSocket has no HTTP tunneling capability.
[xml]
<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:s=”library://ns.adobe.com/flex/spark”
xmlns:mx=”library://ns.adobe.com/flex/mx”
>
<fx:Script>
<![CDATA[

import com.*;
import mx.controls.Alert;
private var _xmlSocket:XMLSocketClient

private function connectToServer(event:MouseEvent):void {
try{
trace(‘Client is trying to connect with server’)
_xmlSocket = new XMLSocketClient()
}
catch(err:Error){
Alert.show(‘error’+err.name);
}
}
private function sendData():void
{
_xmlSocket.send(msg_txt.text);
}
private function onDisconnectClicked():void
{
_xmlSocket.disconnect();
}

]]>
</fx:Script>

<s:Button x=”327″ y=”40″ label=”Disconnect” width=”95″ id=”disconnect_btn” click=”onDisconnectClicked()”/>

<s:Button x=”213″ y=”126″ label=”Send” width=”95″ id=”send_btn” click=”sendData()”/>

<s:TextInput x=”124″ y=”96″ width=”298″ id=”msg_txt” maxChars=”100″/>

<s:Button x=”183″ y=”74″ width=”125″ height=”41″ label=”Connect” click=”connectToServer(event)”/>

</s:Application>
[/xml]

Tags: , , , , , , , , , ,