Friday, June 19, 2009

Build Flash Online - AS3.0 online compiler

This is very interesting stuff that you can explore. If you don't have programming resources for coding in AS3.0 then don't worry. You just need to go to


It really awsome. It has also support for many AS3.0 Libraries like as3corelib, tweener etc.

So you can do some great stuff here without much requirement of resource. Just logon and start coding :)

I will take you through one small example. Lets take a look @ the interface. Its too simple.



You just need to click the red pointed area shown above to start coding.



Doing coding is as simple as putting up some text line in notepad. The only disadvantage or advantage whatever u consider is that you don't get code hints. Lets go with a simple example. All I am trying to do is to create a simple circle and move it through Left and Right arrow.

The thing which i got to know while coding on wonderfl is that all the classes needs to be declared on the same screen - the package, classes etc. So, I need a circle shape which i am simple taking it through a class "snakeNode". This is just an example you can try with your own code.

  1. import flash.display.Sprite;
  2. import flash.geom.Rectangle;
  3. import flash.display.Shape;
  4. import flash.display.DisplayObject;
  5. class snakeNode extends Sprite{
  6. private var child:Shape = new Shape();
  7. public function snakeNode()
  8. {
  9. child.graphics.beginFill(0xFFCC00);
  10. child.graphics.lineStyle(0, 0x666666);
  11. child.graphics.drawCircle(5, 5, 5);
  12. child.graphics.endFill();
  13. addChild(child);
  14. }
  15. }

It goes something like above. Now the main document class where we would use this code.

  1. package {
  2. import flash.display.Sprite;
  3. import flash.events.KeyboardEvent;
  4. import flash.events.MouseEvent;
  5. public class sampleHitTest extends Sprite {
  6. private var mysNode:snakeNode;
  7. public function sampleHitTest() {
  8. init()
  9. }
  10. public function init():void
  11. {
  12. mysNode = new snakeNode();
  13. mysNode.x = 100;
  14. mysNode.y = 200;
  15. addChild(mysNode);
  16. stage.addEventListener(KeyboardEvent.KEY_DOWN,mouseDown);
  17. }
  18. public function mouseDown(event:KeyboardEvent):void
  19. {
  20. if(event.keyCode == 37)
  21. {
  22. mysNode.x-=15;
  23. }
  24. else if(event.keyCode == 39)
  25. {
  26. mysNode.x+=15;
  27. }
  28. }
  29. }
  30. }

In this way you can write your code. It compiles automatically as an when you are writing a code at the bottom.




Here is the complete code how it looks.

  1. package {
  2. import flash.display.Sprite;
  3. import flash.events.KeyboardEvent;
  4. import flash.events.MouseEvent;
  5. public class sampleHitTest extends Sprite {
  6. private var mysNode:snakeNode;
  7. public function sampleHitTest() {
  8. init()
  9. }
  10. public function init():void
  11. {
  12. mysNode = new snakeNode();
  13. mysNode.x = 100;
  14. mysNode.y = 200;
  15. addChild(mysNode);
  16. stage.addEventListener(KeyboardEvent.KEY_DOWN,mouseDown);
  17. }
  18. public function mouseDown(event:KeyboardEvent):void
  19. {
  20. if(event.keyCode == 37)
  21. {
  22. mysNode.x-=15;
  23. }
  24. else if(event.keyCode == 39)
  25. {
  26. mysNode.x+=15;
  27. }
  28. }
  29. }
  30. }
  31. import flash.display.Sprite;
  32. import flash.geom.Rectangle;
  33. import flash.display.Shape;
  34. import flash.display.DisplayObject;
  35. class snakeNode extends Sprite{
  36. private var child:Shape = new Shape();
  37. public function snakeNode()
  38. {
  39. child.graphics.beginFill(0xFFCC00);
  40. child.graphics.lineStyle(0, 0x666666);
  41. child.graphics.drawCircle(5, 5, 5);
  42. child.graphics.endFill();
  43. addChild(child);
  44. }
  45. }

You can also download this script in form of *.as file to use it anywhere you like. Its a great stuff and very useful. Cheers !!!

Nitin :o)

Thursday, June 18, 2009

Adobe BrowserLab

Adobe Browserlab is an application similar to Microsoft SuperPreview that competes with it. Basically, it allows you to test your web site and see how well it works on most popular web browsers. Once signed in, you will be able to choose browsers, operating systems to test and see them side-by-side. It is a flash cloud based application.

Adobe BrowserLab provides Web professionals with real-time accurate screenshots of browser renderings and includes multiple viewing and diagnostic tools to help designers pinpoint compatibility issues that can compromise the design and layout integrity of a Web site or page.

“Cross-browser testing has been one of the biggest challenges for Web designers because it is such an arduous and time-intensive task,” said Lea Hickman, director, Creative Solutions Business Unit at Adobe. “Now with Adobe BrowserLab, designers have a simple solution that enables comprehensive browser compatibility testing in just a matter of minutes, leaving Web designers with more time to be creative and deliver the high-impact sites customers are demanding.”


Key Features of Adobe BrowserLab:
  • Support for all modern browsers and operating systems
  • Eliminates the need to have browsers installed on a system before testing a site.
  • Adobe BrowserLab includes multiple viewing and diagnostic tools to help Web designers easily spot potential issues. For example, designers can view two screenshots from different browsers side-by-side, or they can use the “onion skin mode” to overlay screenshots on top of one another with variable opacity.
  • It provides Adobe Dreamweaver CS4 users extended capabilities to also test Flash technology-based and interactive site elements, including dynamic widgets, rollover effects and AJAX driven content.
Reference Links :

Have you heard of HTML5?

HTML5 is a new standard of the World Wide Web, HTML. The most important and amazing thing about html5 that can let everone thinking about is the "video" html tag. The video tag will make it possible to add video into html webpages and have it playback across different browsers that implements html5.

In addition to basic markup, HTML 5 specifies scripting application programming interfaces (APIs). Existing Document Object Model (DOM) interfaces are extended and de facto features documented. There are also new APIs, such as:

  • The canvas tag for immediate mode 2D drawing
  • Timed media playback
  • Offline storage database
  • Document editing
  • Drag-and-drop
  • Cross-document messaging
  • Browser history management
  • MIME type and protocol handler registration

Source : Wikipedia

The canvas element for drawing graphics on-the-fly is a good example; new in HTML 5, it’s already supported by every major browser except Internet Explorer (and there are workarounds for IE too).

Lesser-known HTML 5 features like offline data storage, cross-document messaging, and access to the back/forward stack, which are mainly of interest to JavaScript developers, are also popping up in the newest browsers, including IE8.

Source : Sitepoint

More Information could be gathered from links below:


-Nitin-

Tuesday, June 16, 2009

Using JavaScript and Flash Integration Kit



The JavaScript and Flash Integration Kit allows developers to get the best of the Flash and HTML worlds by enabling JavaScript to invoke ActionScript functions, and vice versa............
more information can be obtained from below link :


Download link for the Classes and Javascript files below :


I found this technique pretty useful. It works well and we can communicate between JavaScript and Flash quite easily and with more flexibility as it supports passing of Objects and arrays.

For communication we need to import JavaScriptProxy Class.

A sample below :

import com.macromedia.javascript.JavaScriptProxy;

var proxy:JavaScriptProxy = new JavaScriptProxy(_root.lcId, this);

insertBtn.onRelease = function()
{
proxy.call("InsertFunction", nametxt.text, infotxt.text);
}

function displayfromJS(values:Object)
{
infotxt.text = values.Name;
}

Link for the source fla for the code above : http://www.box.net/shared/6mr5v77r4v

"proxy.call("InsertFunction", nametxt.text, infotxt.text)" this line calls a function on the html page with name "insertFunction". It is also taking two parameters here along with function call.

Lets look at the Html file


"example.htm"


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

<html>
<head>
<title>Sample</title>
<script type="text/javascript" src="JavaScriptFlashGateway.js"></script>
<script type="text/javascript">
var lcId = new Date().getTime();
var flashProxy = new FlashProxy(lcId, "JavaScriptFlashGateway.swf");

function InsertFunction(item1,item2) {

alert("Text file will only be created in C:\ if you are using IE = "+item1);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("c:\\Test.txt", true);
fh.WriteLine("Name : "+item1);
fh.Close();
}

function transferItemToFlash() {
var toFlashVal = document.listForm.sendVal.value;
flashProxy.call("displayfromJS", {Name:toFlashVal,Val:"121008250"});
}
</script>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="5" width="400">
<tr>
<td width="116" valign="top">
<script type="text/javascript">
var sample = new FlashTag("main.swf", 216, 120, "7,0,14,0");
sample.setFlashvars("lcId=" + lcId);
sample.write(document);
</script>
</td>
<td width="269" valign="top">
<form name="listForm">
<input type="text" name="sendVal"/>
<input type="Button" value="transfer" onclick="javascript:transferItemToFlash();" />
</form>
</td>
</tr>
</table>

</body>
</html>

As you can notice html file has two javascript functions, "InsertFunction" which is called from flash and "transferItemToFlash" which is used to send data into flash.

var lcId = new Date().getTime();
var flashProxy = new FlashProxy(lcId, "JavaScriptFlashGateway.swf");

Above lines are required create an instance of the FlashProxy JavaScript class and pass in the unique ID you just created, and the path to the JavaScriptFlashGateway.swf file. Further details given at below link:


The final source files along with the required classes can be downloaded from below link.


-Nitin-

Monday, March 23, 2009

Assignment : Interactive dynamic tabbed menu



We had to design a tabbed menu keeping following things in mind.
  • Trace the design close to the layout shown in reference.
  • Menu will be created dynamically from an external XML file and will accept all data like number of tabs and label for each tab etc from XML.
  • Each tab should adjust its width automatically as per the label’s size.
  • If tabs are taking more space than the defined width, it should display two small arrows on both the sides allowing scroll/pan the menu.
  • Selected menu should be highlighted as shown in reference.
  • Please call a function by passing some id for each tabs, for example call showSection(id:Number).
  • Use ActionScript 3.0
I just tried it creating a rough class. It may be helpful to anyone learning AS3.0.
Here I am making one "TabControls" class of which objects could be created. I am using some graphics from library. So i am attaching one fla below which carries all the required symbols.


The designed class also takes one parameter for maskWidth. It limits the width to which the tab control would be visible.
something like

var myTab:TabControls = new TabControls(500); addChild(myTab);

Lets take a look @ the code of the class.

TabControls.as

package
{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
import flash.utils.Timer;
import flash.events.TimerEvent;

public class TabControls extends Sprite
{
private var _urlReq:URLRequest;
private var _urlLoad:URLLoader;
private var _noOfTabs:Number;
private var _externalXML:XML;
private var _tabArray:Array = new Array();
private var _objtab:Array = new Array;
private var _gridX:Number = 50;
private var _gridY:Number = 100;
private var _tabClip:MovieClip = new MovieClip();
private var _clickColorCode:uint = 0xff0000;
private var _defaultColorCode:uint = 0x666666;

private var _maskBground:Sprite = new Sprite();
private var _maskw:Number;
private var _maskh:Number = 28;

private var _leftArrow:leftarw = new leftarw();
private var _rightArrow:rightarw = new rightarw();

private var myTf:TextField = new TextField();
private var _myTimer:Timer;
private var _moveDirection:String;

public function TabControls (maskwidth:Number)
{
_maskw = maskwidth;
init ();
}
public function init ()
{
_urlReq = new URLRequest("tabData.xml");
_urlLoad = new URLLoader(_urlReq);
_urlLoad.addEventListener (Event.COMPLETE,onComplete);
addChild (myTf);
_myTimer = new Timer(100, 0);
_myTimer.addEventListener("timer", timerHandler);
}
public function onComplete (e:Event):void
{
_externalXML = new XML(_urlLoad.data);
_noOfTabs = _externalXML.tabDesc.attribute("nooftabs");
for (var k=0; k<_externalxml.tabs.length(); xx="0;" mousechildren =" false;" buttonmode="true;" name = "tab" text =" _tabArray[xx];" wordwrap="false;" autosize =" TextFieldAutoSize.LEFT;" width =" tabObj.tabText.textWidth" tempx =" 0;" tempy =" _gridY;" jj="0;" x =" tempX;" y =" tempY;" x =" _gridX" uint =" _tabClip.numChildren" ii="0;" colortransform =" _objtab[ii].tabBg.bgColor.transform.colorTransform;" color =" _defaultColorCode;" colortransform =" newColorTransform1;" colortransform =" _objtab[clickCode].tabBg.bgColor.transform.colorTransform;" color =" _clickColorCode;" colortransform =" newColorTransform;" x =" _gridX-2;" y =" _gridY-2;" mask =" _maskBground;" buttonmode =" true;" buttonmode =" true;" x =" _maskBground.x" y =" _maskBground.y" x =" _maskBground.x+_maskBground.width" y =" _maskBground.y" x =" _maskBground.x" y =" _maskBground.y" _movedirection = "right" _movedirection = "left" autosize =" TextFieldAutoSize.LEFT;" text =" _tabArray[id];" _movedirection ="="" x =" _tabClip.x" _movedirection ="=""> (_maskBground.width-_tabClip.width+_gridX))
{
_tabClip.x = _tabClip.x - 10;
}
}
}
}
}


he constructor of the class transfers the parameter for maskwidth to a local private var.
As you can notice the init() method of the class is loading all the XML and then latter "onComplete" event method is used to populate the array with values reading it from the XML.

The method "generateTabs()" create instance of "tabBox" a linked class found in the library of the fla linked above in article.

public function generateTabs()
{
for(var xx=0;xx<_tabarray.length;xx++)
{
_objtab[xx] = new tabBox();
_objtab[xx].name = "tab"+xx;
_objtab[xx].tabText.text = _tabArray[xx];
formatTab(_objtab[xx]);
}
addTabs();
}

The method "formatTab()" was required so that the width of the tabs could be dynamically be controlled.

tabObj.tabText.autoSize = TextFieldAutoSize.LEFT;

The autosizing code and then calculating it with the background clip allows us the reach the goal.
Finally "addTabs()" method allows us to add the tabs..on the stage.

The method arranges in such a way that it views as tabs. The "addMasktoTabs()" method has been added to limit the view area of the tabControl. It uses the same "maskwidth" parameter which we passed to the constructor of the class.

One very important method is "onRollTab()"

public function onRollTab(e:MouseEvent):void
{
var topPosition:uint = _tabClip.numChildren - 1;
_tabClip.setChildIndex(_objtab[e.currentTarget.name.substr(3,2)], topPosition);
}

This method is basically doing the depth management of the tabs. It is checking all the childs in the MovieClip container "_tabClip" and then swapping the rolledover tab to highest index.

All associated files can be downloaded from below link.


-Nitin

Tuesday, March 10, 2009

duplicateDisplayObject (Duplicate Clip) using Senocular Class



I was just trying to duplicate a MovieClip when i got this a very good class from senocular library.


This class helps in duplicating the clips.

Here in example i have created a circle Sprite and i am duplicating it with the senoclular class.

The basic idea that i felt was that, you can duplicate the object after it is added to stage. Please reply me if anyone of you get any understanding of it. I am new to AS3.0 n hv just started learning.

Consider a simple class. This could be anything but for simplicity i am taking it.

doubleRed.as

package {
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.MovieClip;
public class doubleRed extends Sprite{
public function doubleRed()
{
graphics.beginFill(0x00ff00);
graphics.drawCircle(50,50,15);
graphics.endFill();
}
}
}

Look @ this Flash File code.

var db:doubleRed = new doubleRed();
addChild(db);
var newInstance:DisplayObject = duplicateDisplayObject(db, true);
newInstance.x = 200;
newInstance.addEventListener(MouseEvent.MOUSE_DOWN,dragme);
newInstance.addEventListener(MouseEvent.MOUSE_UP,stopme);

function dragme(event:MouseEvent):void{
event.target.startDrag();
}

function stopme(event:MouseEvent):void{
event.target.stopDrag();
}

var newInstance1:DisplayObject = duplicateDisplayObject(db, true);
newInstance1.addEventListener(MouseEvent.MOUSE_DOWN,dragme);
newInstance1.addEventListener(MouseEvent.MOUSE_UP,stopme);

I have just created the instance and first added it to the stage.

You can download all the realated files from below link.


-Nitin

Using FormBuilder, Validators & FormGroup in Angular 2 to post data to Node server (node.js)

This blog explains usage of  FormBuilder , Validators , FormGroup classes in Angular 2 projects. In this post we will create HTML form a...