Archive for the ‘Flash AS 3.0’ Category

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

December 22nd, 2011 by admin | No Comments | Filed in 100 Useful Classes in AS 3.0 For Game Programming, Flash AS 3.0, Flex (RIA), Games Programming

images

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);
			}
		}

	}

}

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

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

December 22nd, 2011 by admin | 1 Comment | Filed in 100 Useful Classes in AS 3.0 For Game Programming, Flash AS 3.0, Flex (RIA), Games Programming

images

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 ); 

		}  

	}

	}

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

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

December 22nd, 2011 by admin | 1 Comment | Filed in 100 Useful Classes in AS 3.0 For Game Programming, Flash AS 3.0, Flex (RIA), Games Programming

images

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);
		}

	}
}

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

Introducing a new section ‘Forum’

December 3rd, 2011 by admin | 1 Comment | Filed in Flash AS 3.0

I am the admin of Dremsus very happy to announce that we have added a new section the ‘Forum’ for all techies :)

Direct Link : http://forum.dremsus.com

dremsus_forum

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

Flex 4.5 and AmfPhp connection and Data transfer

November 16th, 2011 by admin | No Comments | Filed in AmfPHP, Communication between Flex and External Environment, Flash AS 3.0, Flex (RIA)

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.


fname = "Aava";

$emp->lname = "Anjan";

$emp->age = 28;

return $emp;

}

}

?>

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



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 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>

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

flex_result

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

RelativeLayout in Android

November 15th, 2011 by admin | 1 Comment | Filed in Android Tutorials, Flash AS 3.0, Types of Views

droid_tool

RelativeLayout is a ViewGroup that displays child View elements in their relative positions.
The position of a View is as relative to elements.
This example is for Relative Layout :

Steps :
Step 1. Create a new android project.
Step 2. Give the project name.
Step 3. Open res/layout/main.xml

Step 4. Here is the code :



Step 5.Run you app. it will look like this :
RelativeLayout

Tags: , , , , ,

How to transfer Array within an Object to JavaScript using External Interface ?

November 4th, 2011 by admin | No Comments | Filed in Adobe Certifications, Communication between Flex and External Environment, External Interface, Flash AS 3.0, Flex (RIA)
Here is an example :
Flex Side :
<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application
xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:mx=”library://ns.adobe.com/flex/mx”
xmlns:s=”library://ns.adobe.com/flex/spark”>
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<fx:Script><![CDATA[
import flash.external.*;
public function callJavaScriptFunction():void {
var msg:String;
if (ExternalInterface.available) {
var _obj:Object = new Object();
_obj.fname = "Aava";
_obj.lname = "Rani";
_obj.familly = new Array('RP','AK','SK','BK');
msg = ExternalInterface.call('receiveComplexDataTypes', _obj);
} else {
msg = "Not available";
}
}
]]></fx:Script>
<s:Button label=”Send Data” click=”callJavaScriptFunction()”/>
</s:Application>
HTML Side :-
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” lang=”en” xml:lang=”en”>
<head>
<title>Complex Data and ExternalInterface Example</title>
<script type=”text/javascript” src=”swfobject.js”></script>
<script type=”text/javascript”>
var swfVersionStr = “0″;
var xiSwfUrlStr = “”;
var flashvars = {};
var params = {};
params.quality = “high”;
params.bgcolor = “#ffffff”;
params.allowscriptaccess = “sameDomain”;
var attributes = {};
attributes.id = “ComplexDataExternalInterface”;
attributes.name = “ComplexDataExternalInterface”;
attributes.align = “middle”;
swfobject.embedSWF(
“ComplexDataExternalInterface.swf”, “flashContent”,
“100%”, “100%”,
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
</script>
</head>
<SCRIPT LANGUAGE=”JavaScript”>
function receiveComplexDataTypes(object) {
var str = (”The Data values are :- ” + object.fname + ” \n and :-” + object.lname + “!”);
for (i=0; i<object.familly.length; i++) {
str +=  i + “: ” + object.familly [i] + “\n”;
}
alert(str);
return “successful”;
}
</SCRIPT>
<body>
<div id=”flashContent”/>
</body>

Here is an example :

Flex Side :


<?xml version="1.0" encoding="utf-8"?>

<s:Application

xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:mx="library://ns.adobe.com/flex/mx"

xmlns:s="library://ns.adobe.com/flex/spark">

<s:layout>

<s:HorizontalLayout/>

</s:layout>

<fx:Script><![CDATA[

import flash.external.*;

public function callJavaScriptFunction():void {

var msg:String;

if (ExternalInterface.available) {

var _obj:Object = new Object();

_obj.fname = "Aava";

_obj.lname = "Rani";

_obj.familly = new Array('RP','AK','SK','BK');

msg = ExternalInterface.call('receiveComplexDataTypes', _obj);

} else {

msg = "Not available";

}

}

]]></fx:Script>

<s:Button label="Send Data" click="callJavaScriptFunction()"/>

</s:Application>

HTML Side :-


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>

<title>Complex Data and ExternalInterface Example</title>

<script type="text/javascript" src="swfobject.js"></script>

<script type="text/javascript">

var swfVersionStr = "0";

var xiSwfUrlStr = "";

var flashvars = {};

var params = {};

params.quality = "high";

params.bgcolor = "#ffffff";

params.allowscriptaccess = "sameDomain";

var attributes = {};

attributes.id = "ComplexDataExternalInterface";

attributes.name = "ComplexDataExternalInterface";

attributes.align = "middle";

swfobject.embedSWF(

"ComplexDataExternalInterface.swf", "flashContent",

"100%", "100%",

swfVersionStr, xiSwfUrlStr,

flashvars, params, attributes);

</script>

</head>

<SCRIPT LANGUAGE="JavaScript">

function receiveComplexDataTypes(object) {

var str = ("The Data values are :- " + object.fname + " \n and :-" + object.lname + "!");

for (i=0; i<object.familly.length; i++) {

str +=  i + ": " + object.familly [i] + "\n";

}

alert(str);

return "successful";

}

</SCRIPT>

<body>

<div id="flashContent"/>

</body>

Tags: , , , , , , , ,

Starling -Gaming with 2D hardware rendering

October 13th, 2011 by admin | 1 Comment | Filed in Flash AS 3.0, Flex (RIA), Games Programming

The Straling:
What is Starling ? :-
a)Starling is an ActionScript 3 2D framework developed based on the Stage3D APIs
b)Starling for the desktop in Adobe Flash Player 11 and Adobe AIR 3.
c)Starling is specially designed for the game development
d)Starling makes it possible to write fast GPU accelerated applications without having to touch the low-level Stage3D APIs.
e)Starling is designed for ActionScript 3 developers, especially those involved in 2D game development.
f) Starling is lightweight, flexible and easy to use.

will discuss few tutorials soon.

Future of New Media

October 13th, 2011 by admin | 1 Comment | Filed in Flash AS 3.0, Flex (RIA), Games Programming

I am developer of all these four platform :

a) Native iOs

b) Android

c)Flash/Flex

d) HTML5

On the basis of my experience in these technologies I would like to share my views about Future of New Media.

I found few Facts about the wide area presence of Flash Player from the various online resources :

75% of all video on the web is viewed with Flash Player.
Flash Player is on 99% of all connected PCs.
85 % of 100 top websites use Flash
95% of top 20 phone OEMs will deliver Flash

so what is the present of flash in New Media Space :
1. Already grown a lot.
2. Still growing.
3. Have a large foot print in the sector of media,game etc.

And what is the future:
1. The new version will come as the replacement of fastly growing Unity3D.
2. The new version with a great performnace feature like hardware rendering will change the
gaming industry and mobile world.
3. In future Flash will be the cheapest medium to develope game/app or video for all platform with its great performance.
4. The Adobe AIR3 going to make a great presence in the field of television and desktop app world.
The Stage Video having :
a)smoothest, highest quality, seamless video
b)lowest CPU usage, longest battery life
c)optimized for multi-screen: PC, smartphone, tablet, television
d)reaching also out to low-end PC devices

All the best Adobe :) :)

Exporting Images from AIR

March 1st, 2011 by admin | No Comments | Filed in Flash AS 3.0, Flex (RIA), Games Programming

333

Lets learn today to export images in png and jpeg format from AIR . It will be simillar to the drawing application where
we draw something and export it as images.

Step 1:
Download the Encoder classes from Adobe
For Saving the image we have used here File,FileStream and FileMode classes.
Here you can save your avatar in both png and jpeg format.

Step 2:
I have designed a mc MovieClip in the stage . Now I will choose the
different colors after completing the color changing option
will save the image in format of PNG or JPEG.

Here I will place color picker components for
Colour option for the MovieClip.

Step 3:
Many of have faced or facing the problem of transparency in PNG format files.
here is the solution add follwing parameter in the new instance of BitmapData
like I have added here :
‘new BitmapData(mc.width,mc.height,true,0xDEDEDE)’;

Here is your complete code :

package{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileStream;
	import flash.filesystem.FileMode;
	import flash.events.Event;
	import flash.display.BitmapData;
	import flash.utils.ByteArray;
	import fl.events.ColorPickerEvent;
	import flash.geom.ColorTransform;
	import flash.text.TextFormat;
	import flash.text.Font;
	/*

	*/

	import com.adobe.images.PNGEncoder;
	import com.adobe.images.JPGEncoder;
	import flash.display.MovieClip;
	import fl.motion.Color;

	public class Main extends MovieClip{
		private var _fileRef:File = File.documentsDirectory;
		private var imageByteArray:ByteArray;
		private var _fileType:String;

		function Main(){
			init();
		}

		/*

		*/
		private function init():void{
			handleColorpicker();
			save_btn.addEventListener(MouseEvent.MOUSE_DOWN,onEncode);
		}

		private function handleColorpicker():void{
			colorPickerShirt.addEventListener(ColorPickerEvent.CHANGE,onColorChange);

		}
		private function onEncode(e:MouseEvent):void{
			switch(img_radio_btn.selected){
				case true:
					saveAsJPG();
					break;
				case false:
					saveAsPNG();
					break;
			}
		}

		private function getBitmapData():BitmapData{
			var bd:BitmapData = new BitmapData(mc.width,mc.height,true,0xDEDEDE);
			bd.draw(mc);
			return bd;
		}
		private function saveAsPNG():void{
            imageByteArray = PNGEncoder.encode(getBitmapData());
			browseForSave("PNG");
		}
		private function saveAsJPG():void{
			var jpgEncoder:JPGEncoder = new JPGEncoder(100);
            imageByteArray = jpgEncoder.encode(getBitmapData());
			browseForSave("JPG");
		}
		private function browseForSave(fileType:String):void{
			_fileType = fileType;
			_fileRef.browseForSave("Save As " + fileType);
   			_fileRef.addEventListener(Event.SELECT, onSaveAsSelected);
		}
		private function onSaveAsSelected(e:Event):void{
			_fileRef = e.target as File;
			var ext:String;
			switch(_fileType){
				case "JPG":
					ext = ".jpg";
					break;
				case "PNG":
					ext = ".png";
					break;
			}
			if(_fileRef.extension == null){
				_fileRef.nativePath += ext;
			}
			var stream:FileStream = new FileStream();
			stream.open(_fileRef, FileMode.WRITE);
			stream.writeBytes(imageByteArray, 0, imageByteArray.length);
			stream.close();
		}

		private function onColorChange(e:ColorPickerEvent):void{		

			ChangeObjectColor(mc, e.target.selectedColor)

		}

		private function ChangeObjectColor(_mc:MovieClip,_color:uint):void{
			var colorTransform:ColorTransform;
			colorTransform = _mc.transform.colorTransform;
			colorTransform.color = _color;
			_mc.transform.colorTransform = colorTransform;
		}

	}
}