August 25, 2008
The swapDepth is not available on AS3, rather much more simplest way is available.
The below commented code can be achieved through the single line:
event.target.parent.addChild(event.target);
private var _dragIcon:MovieClip;
dragIcon.addEventListener(MouseEvent.MOUSE_UP,onMouseUp, false, 0, true);
dragIcon.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown, false, 0, true);
/*
private var oldSwapDepth:int = 0;
private var tempSwapDepth:int = 0;
private function onMouseDown(event:MouseEvent):void
{
dragIcon.startDrag(false)
tempSwapDepth = dragIcon.parent.getChildIndex(dragIcon);
var newSwapDepth:int = dragIcon.parent.getChildIndex(swapDepthMc);
newSwapDepth>oldSwapDepth ? newSwapDepth = newSwapDepth : newSwapDepth = oldSwapDepth;
dragIcon.parent.setChildIndex(dragIcon,newSwapDepth)
oldSwapDepth = dragIcon.parent.getChildIndex(dragIcon);
}
private function onMouseUp(event:MouseEvent):void {
dragIcon.stopDrag();
dragIcon.parent.setChildIndex(dragIcon,tempSwapDepth);
} */
private function onMouseDown(event:MouseEvent):void
{
event.target.parent.addChild(event.target);
}
2 Comments |
Flex | Tagged: as2, as3, drag, drag and drop, drop, Flex, setChildIndex, swapDepth |
Permalink
Posted by nsdevaraj
August 21, 2008
1. Tell any loaded .swf child assets to disable themselves.
2. Stop any sounds from playing.
3. Stop the main timeline, if it is currently playing.
4. Stop any movie clips that are currently playing.
5. Close any connected network objects, such as instances of Loader, URLLoader, Socket, XMLSocket, LocalConnection, 6. NetConnections, and NetStream.
7. Release all references to cameras and microphones.
8. Remove all event listeners
9. Stop any currently running intervals (via clearInterval()).
10. Stop any Timer objects (via the Timer class’s instance method stop()).
11. Dispose all subobjects
12. Release all references to external objects
In future Flash Player 10, does these by calling the Loader class’s new method unloadAndStop().
6 Comments |
Flex | Tagged: as3, Flex, swf, unload, unloadmovie |
Permalink
Posted by nsdevaraj
August 21, 2008
<mx:states>
<mx:State name=”minimized”>
<mx:SetProperty target=”{this}” property=”height” value=”{this.minHeight+15)}”/>
<mx:SetProperty target=”{this}” property=”width” value=”{this.minWidth}”/>
<mx:SetProperty target=”{this}” property=”vScrollPolicy” value=”off”/>
<mx:SetProperty target=”{this}” property=”hScrollPolicy” value=”off”/>
</mx:State>
</mx:states>
private function buildStates():void{
var overrides:Array = new Array();
var newState:State = new State();
overrides.push(makeSetProp(this,”height”,this.minHeight +5));
overrides.push(makeSetProp(this,”width”,this.minWidth));
overrides.push(makeSetProp(this,”vScrollPolicy”,”off”));
overrides.push(makeSetProp(this,”hScrollPolicy”,”off”));
newState.name=”minimized”;
newState.overrides = overrides;
this.states = new Array(newState);
}
private function makeSetProp(target:UIComponent, property:String, value:*):SetProperty{
var sp:SetProperty = new SetProperty();
sp.target = target;
sp.property = property;
sp.value = value;
return sp;
}
1 Comment |
Flex | Tagged: as3, convert, Flex, mxml, State |
Permalink
Posted by nsdevaraj
August 21, 2008
on()/onClipEvent():
AS2:
on (release) {
this._parent.gotoAndPlay(1);
}
AS3:
replayBtn.addEventListener(MouseEvent.CLICK, replayBtnClickListener);
function replayBtnClickListener (e) {
gotoAndPlay(1);
}
or
replayBtn.addEventListener(MouseEvent.CLICK, function (e) {
gotoAndPlay(1);
});
Delegate Class:
The Delegate Class of AS2, is more simpler to write in AS3 as like the example below:
AS2:
myButton.addEventListener(“click”, Delegate.create(this, someMethod));
Delegate.create(this, someMethod)
AS3:
myButton.addEventListener(“click”, someMethod);
loadMovie
AS2:
theClip.loadMovie(“animation.swf”);
AS3:
var l:Loader = new Loader();
l.load(new URLRequest(“animation.swf”));
theParent.addChild(l);
Controlling Parent Movie Clips
AS2:
this._parent.play();
AS3:
MovieClip(this.parent).play();
or
this.parent["play"]();
Removal of getURL()
AS2:
getURL(“http://nsdevaraj.wordpress.com/”);
AS3:
navigateToURL(new URLRequest(“http://nsdevaraj.wordpress.com/));
AS3 class to use getURL:
package {
import flash.net.*;
public function getURL (url:String,
window:String = “_self”):void {
var u:URLRequest = new URLRequest(url);
navigateToURL(u, window);
}
}
Usage:
getURL(“http://nsdevaraj.wordpress.com/”);
or
getURL(“http://nsdevaraj.wordpress.com/”, “_blank”);
createTextField:
AS2
someClip.createTextField(“t”,0, 0, 0, 100, 100);
someClip.t.text = “Hello world”;
AS3
var t:TextField = new TextField();
t.text = “Hello world”;
eval Objects:
AS2:
for (var i = 0; i < 10; i++) {
parentClip.attachMovie(“Animation” + i, “instance” + i, i);
}
AS3:
var Symbol:Object;
for (var i:int = 0; i < 10; i++) {
Symbol = getDefinitionByName(“Animation” + i);
parentClip.addChild(new Symbol());
}
attachMovie:
AS2:
parentClip.attachMovie(“Animation”, “instance” , 1);
AS3:
package {
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
import flash.utils.getDefinitionByName;
public function addChildFromLibrary (parent: DisplayObjectContainer,
symbolName:String,
depth:int = -1): DisplayObject {
var Symbol = getDefinitionByName(symbolName);
if (depth < 0) {
return parent.addChild(new Symbol());
} else {
return parent.addChildAt(new Symbol(), depth);
}
}
}
Usage:
addChildFromLibrary(parentClip, “Animation”);
duplicateMovieClip()
AS2:
duplicateMovieClip (circle, “circle1″, 1);
AS3:
package {
import flash.display.DisplayObject;
import flash.geom.Rectangle;
import flash.system.Capabilities; // version check for scale9Grid bug
public function duplicateDisplayObject(target: DisplayObject, autoAdd:Boolean = false): DisplayObject {
var targetClass:Class = Object(target).constructor;
var duplicate: DisplayObject = new targetClass() as DisplayObject;
// duplicate properties
duplicate.transform = target.transform;
duplicate.filters = target.filters;
duplicate.cacheAsBitmap = target.cacheAsBitmap;
duplicate.opaqueBackground = target.opaqueBackground;
if (target.scale9Grid) {
var rect:Rectangle = target.scale9Grid;
if (Capabilities.version.split(” “)[1] == “9,0,16,0″){
// Flash 9 bug where returned scale9Grid as twips
rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20;
}
duplicate.scale9Grid = rect;
}
// add to target parent’s display list
// if autoAdd was provided as true
if (autoAdd && target.parent) {
target.parent.addChild(duplicate);
}
return duplicate;
}
}
Usage:
var circle1:MovieClip = duplicateDisplayObject(circle, true);
Leave a Comment » |
Flex | Tagged: as2, as3, attachMovie, createTextField, Delegate, duplicateMovieClip, eval, getURL(), loadMovie, MovieClip controls, on()/onClipEvent(), remedu |
Permalink
Posted by nsdevaraj
August 21, 2008
1. Declare types for all variables, parameters, and return values.
2. Declarations with no access specifier now default to package internal, not public.
3. Classes are sealed by default, meaning properties cannot be added dynamically at runtime.
4. Use package declarations to put a class definition into a package.
5. Import classes, even if references to the class are fully qualified.
6. Always mark method overrides. Declare return types in your functions.
7. Delegates are now built into the language, making event dispatching easier.
8. De referencing a null or undefined reference will throw an exception.
9. For debugging use the -verbose-stacktraces and -debug options.
10. Explicitly declare properties to be bindable.
11. Flash Player API has been reorganized into packages.
12. Use the new Timer class instead of setInterval/setTimeout.
13. Be sure to subclass events.
14. Visual elements must extend DisplayObject, and define them like any other class.
15. E4X (ECMAScript for XML) is used for manipulating XML.use toXMLString() method when using E4X.
16. for…in loop will not enumerate properties and methods declared by a class.
Leave a Comment » |
Flex | Tagged: as2, as3, conversion, convert, Flex, guide, migration, steps |
Permalink
Posted by nsdevaraj
August 20, 2008
This post have three significant solutions:
1. ArrayCollection output into XML
2. Converting any MySQL DB values into XML using PHP
3. Simple Login form using PHP and MXML
The below php code converts db output as xml dbtoxml.php
// <?php
// define(“HOSTNAME”,”localhost”);
// define(“USERNAME”,”root”);
// define(“PASSWORD”,”");
// define(“DB_NAME”,”users”);
// define(“TABLE_NAME”,”users”);
// mysql_connect(HOSTNAME, USERNAME, PASSWORD);
// mysql_select_db(DB_NAME);
// $result = mysql_query(“SELECT * FROM “.TABLE_NAME);//Get the number of rows
// $num_row = mysql_num_rows($result);
// echo ‘<?xml version=”1.0″ encoding=”iso-8859-1″?>’;//Start the output of XML
// echo “<data>”;
// echo ‘<num>’ .$num_row. ‘</num>’;
// if (!$result) {
// die(‘Query failed: ‘ . mysql_error());
// }
// /* get column metadata – column name */
// $i = 0;
// while ($i < mysql_num_fields($result)) {
// $meta = mysql_fetch_field($result, $i);
// $ColumnNames[] = $meta->name; //place col name into array
// $i++;
// }
// $specialchar = array(“&”,”>”,”<”); //special characters
// $specialcharReplace = array(“&”,”>”,”<”); //replacement
// /* query & convert table data and column names to xml*/
// $w = 0;
// while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
// echo “<row>”;
// foreach ($line as $col_value){
// echo ‘<’.$ColumnNames[$w].’>’;
// $col_value_strip = str_replace($specialchar, $specialcharReplace, $col_value);
// echo $col_value_strip;
// echo ‘</’.$ColumnNames[$w].’>’;
// if($w == ($i – 1)) { $w = 0; }
// else { $w++; }
// }
// echo “</row>”;
// }
// echo “</data>”;
// mysql_free_result($result);
// ?>
The below mxml file converts php ArrayCollection output into XML dbconnect.mxml
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”horizontal” creationComplete=”dbconnect.send();”>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
public var XMLNodeObjXMLList:XMLList;
[Bindable] public var loggedIn:Boolean;
public function checkLogin():void {
var userName:String = userId.text;
var passWord:String = pwd.text;
var passList:XMLList = XMLNodeObjXMLList.record.(user == userName);
loggedIn = String(passList.pass) == passWord;
loggedIn ? Alert.show(‘Logged In’) : Alert.show(‘Try Again’);
}
private function resultHandler(e:ResultEvent):void {
XMLNodeObjXMLList = ObjToXmlList(e.result.data.row);
}
private function ObjToXmlList(XMLArrCol:ArrayCollection):XMLList {
var XMLStr:String = “<?xml version=\”1.0\” encoding=\”UTF-8\”?>\n<data>”;
for each(var XMLNodeObj:Object in XMLArrCol) {
XMLStr += “<record>”;
XMLStr += “<user>” + XMLNodeObj.user + “</user>”;
XMLStr += “<pass>” + XMLNodeObj.pass + “</pass>”;
XMLStr += “</record>”;
}
XMLStr += “\n</data>”;
return new XMLList(XMLStr);
}
]]>
</mx:Script>
<mx:HTTPService id=”dbconnect” showBusyCursor=”true” url=”http://localhost/dbtoxml.php” useProxy=”false” result=”resultHandler(event)” />
<mx:Form visible=”{!loggedIn}” includeInLayout=”{!loggedIn}”>
<mx:FormItem label=”Username : “> <mx:TextInput id=”userId” text=”deva” />
</mx:FormItem>
<mx:FormItem label=”Password : “>
<mx:TextInput id=”pwd” displayAsPassword=”true” text=”deva” />
</mx:FormItem>
<mx:FormItem>
<mx:Button label=”Login” click=”checkLogin()”/>
</mx:FormItem> </mx:Form>
<mx:HBox visible=”{loggedIn}” includeInLayout=”{loggedIn}”>
<mx:Label text=”Logged In”/>
</mx:HBox>
2 Comments |
Flex | Tagged: ArrayCollection, as3, Flex, Login, Login Form, mxml, MySQL, MySQL to XML, php |
Permalink
Posted by nsdevaraj
August 7, 2008
Download Flex code Generator on this link : FCG
This helps generating basic source files required for cairngorm, puremvc of a Flex Project
Also, generates PHP source files for SQL database administrations
1 Comment |
Flex | Tagged: as3, cairngorm, code, code generation, fcg, Flex, php, puremvc, sql |
Permalink
Posted by nsdevaraj
August 5, 2008
Steps to Install eclipse-monkey plugin
1. Inside FlexBuilder to to Help-> Software Updates-> Find and Install
2. Search new features to install
3. Add New Remote Site (enter name and url (http://download.eclipse.org/technology/dash/update)
4. Click finish to check for updates and install Eclipse Monkey
5. Restart Flex Builder
6. paste js files inside scripts folder (http://nsdevaraj.googlepages.com/scripts.zip)
Generation In Action
Inside any as file
type ->
name:String
Select it and press Alt +1
type ->
addEventListener(MouseEvent.MOUSE_OVER,
press Alt + 2
type ->
Capital Letters – TITLESTR
Select it and press Alt + 3
Check the magic
2 Comments |
Flex | Tagged: as3, eclipse, generation, Getter, monkey, plugin, Setter |
Permalink
Posted by nsdevaraj