Arul's Blog On Multimedia, Flash MX, Director And Dreamweaver MX
Recent Entries | Guest Book | QuickView | XML-RSS feed | My Profile | Home
::: About this Blog :::
Welcome to Arul's Blog!
Weblog on Multimedia,
Macromedia Flash MX Flash MX
Macromedia Director Shockwave Studio 8.51 Director
Macromedia Dreamweaver MX Dreamweaver MX
View my profile And me :)
Here I'm going to share my views, opinions and code with you all.

::: Services :::

:. ActionScript Highlighting
:. AS Highlighter v2 new!


::: ActionScript :::
:. toString
:. skipCache
:. getWords
:. getDateFromString
:. colorUtils
:. XMLNode-transformTags
:. Object-copyProperties
:. Object-clone

::: ActionScript 2 :::
:. XMLHighlighter
:. PriorityQueue

::: Archives :::
[September 2002]
[October 2002]
[November 2002]
[December 2002]
[January 2003]
[February 2003]
[March 2003]
[April 2003]
[May 2003]
[June 2003]
[July 2003]
[September 2003]
[October 2003]
[December 2003]
[January 2004]
[February 2004]
[March 2004]
[April 2004]
[May 2004]
[June 2004]
[July 2004]
[December 2004]
[January 2005]
[February 2005]
[March 2005]
[May 2005]
[June 2005]
[July 2005]
[August 2005]
[June 2006]
[July 2006]
[November 2006]
[December 2006]
[January 2007]

::: Time Zone :::
All Times on this blog are
GMT + 5:30 Hours
(Indian Standard Time)

::: Flash Resources :::
:. Flash Components
:. Were-Here Forum
:. Digital Illusion
:. Flashmove Forum
:. Flash Goddess
:. Prototypes
:. Actionscript Toolbox
:. UltraShock
:. Chattyfig
:. Full as a Goog
:. Flog

::: Flashers :::
:. Mike Chambers
:. Greg Burch
:. Branden Hall
:. Samuel Wan
:. Stuart Schoneveld
:. Guy Watson
:. Robin Debreuil
:. Mario Klingemann
:. Moises
:. Aral Balkan
:. Peter Hall
:. Josh Dura
:. Alessandro
:. Brajeshwar
:. Nik Khilnani

::: Small Print :::

© Copyright 2002
R.Arul Kumaran

[Made with Blogger]


Tuesday, July 25, 2006

Examples.Flex 2: Enhancing the Blog Reader Example.

In the Live docs you might have read about Retrieve and Display Data. Here I've enhanced the same MXML by the following

  • The LinkButton hidden until the datagrid change event is fired.
  • Enabled the Data Tips for 'Posts' column to show tool tips text on roll over.
  • Made it a scalable layout by using constraint-based layout.

Here is the MXML code, I've highlighted the changes by bold, compare it with the original, compile and see for your self


<?xml version="1.0" encoding="UTF-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="feedRequest.send()" minHeight="360" minWidth="500">
 <mx:HTTPService id="feedRequest" url="http://weblogs.macromedia.com/mchotin/index.xml" useProxy="false"/>
 <mx:Panel left="10" top="10" bottom="10" right="10" layout="absolute" title="BlogReader ({feedRequest.lastResult.rss.channel.title})">
  <mx:DataGrid id="dgPosts" left="20" right="20" top="20" bottom="125" dataProvider="{feedRequest.lastResult.rss.channel.item}" change="openLinkButton.visible=true">
   <mx:columns>
    <mx:DataGridColumn headerText="Posts" dataField="title" showDataTips="true"/>
    <mx:DataGridColumn headerText="Date" dataField="pubDate"/>
   </mx:columns>
  </mx:DataGrid>
  <mx:TextArea left="20" right="20" bottom="46" height="75" htmlText="{dgPosts.selectedItem.description}"/>
  <mx:LinkButton id="openLinkButton" right="20" bottom="20" label="Read Full Post" click="navigateToURL(new URLRequest(dgPosts.selectedItem.link));" visible="false"/>
 </mx:Panel>
</mx:Application>

posted by Arul | link | ^top | next> | add comment
Wednesday, July 19, 2006

Tips.AMFPHP: Sending Arrays with offset Index.

Last time we saw the problem with sending ActionScipt 3 Associative Array. Now we let us see where associative arrays can help.
Lets Make an Array with offset index in PHP:
$arr =array(5=>5);
in ActionScript:
var arr:Array= [];
arr[5]=5;
Sending these arrays either way they go with the missing indices filled with null, so the PHP array comes to flash as
arr=[null, null, null, null, null, 5];
flash array goes to PHP as
$arr=array(NULL, NULL, NULL, NULL, NULL, 5);
This happens in AS1 and AS2 remoting as well.
For an offset of 5 this may be fine, but think about 1000 and above. Solution to this problem is simple, we just need to convert this to associative array by defining one string based key, then the unwanted null values will be gone.

posted by Arul | link |<prev. | ^top | next> | comments [1]
Monday, July 17, 2006

Code.Flash 9: Webcam Motion Detection using AS3 - Source Released.

I rewrote the webcam motion detection example in Actionscript3 using Flash 9 Alpha. You can see the demo here.

As I promised earlier the FLA is ready for download here :)

posted by Arul | link |<prev. | ^top | next> | add comment
Thursday, July 13, 2006

Demo.Flash 9: Webcam Motion Detection using AS3.

Some time back Guy Watson wrote an article in the developer center called Webcam Motion Detection: Using the BitmapData API in Flash 8. He later made a better version of it and included that source in the zip file.

I went through that code and completely rewrote it in ActionScript 3. Here is the demo. This one of course requires a webcam and flash 9 player to play around.

Once I clean up the code I will post the source as well :)

posted by Arul | link |<prev. | ^top | next> | comments [5]
Wednesday, July 12, 2006

Examples.Flash 9: Understanding AMF0 and AS3 Array.

You might have already read about Array oddity in AMFPHP/Flex 2. AS3 Associative Arrays, when sent through AMF0 they include 'length' propery. But numeric index based Arrays are fine.

I've created the following AMFPHP Service to showcase this issue. It is a simple service with a remote method that converts any given object to string and returns it.
<?
class AS3ArrayTest{
  function AS3ArrayTest(){
    @include_once("AS3ArrayTest.methodTable.php");
  }
  /**Converts the given data to String and returns it
  *@param Data Any, Data that needs to be converted
  *@access remote
  *@returns String
  */
  function convertToString($data){
    $str = "PHP dataType: ".gettype($data)."\n";
    $str .= print_r($data, true); 
    return $str;
  }
}
?>

Then I've created a Flash 9 AS3 Fla to send different combinations of data to this service. here is the script that does it all.
  1. import flash.net.Responder;
  2. var conn : RemotingConnection = new RemotingConnection( "http://localhost/amfphp/gateway.php");
  3. //
  4. var simpleArray=[9,8,7];
  5. conn.call( "AS3ArrayTest.convertToString", new Responder(onResult1,null), simpleArray);
  6. //
  7. var associativeArray=[1,2,3]
  8. associativeArray['key']='value';
  9. conn.call( "AS3ArrayTest.convertToString", new Responder(onResult2,null), associativeArray);
  10. //
  11. var object ={key:'value'}
  12. conn.call( "AS3ArrayTest.convertToString", new Responder(onResult3,null), object);
  13. //
  14. var objectWithArray ={key:'value', simpleArray:[4,5]}
  15. conn.call( "AS3ArrayTest.convertToString", new Responder(onResult4,null), objectWithArray);
  16. //
  17. function onResult1( result ) : void{
  18. t1_txt.text=result
  19. }
  20. //
  21. function onResult2( result ) : void{
  22. t2_txt.text=result
  23. }
  24. //
  25. function onResult3( result ) : void{
  26. t3_txt.text=result
  27. }
  28. //
  29. function onResult4( result ) : void{
  30. t4_txt.text=result
  31. }

Here is the result.

Now we can clearly see what is happening. so here is what I suggest
  • If you need to send index based Array, no problem use Array
  • If you need to send key value pairs, use Object instead
  • If you can ignore the 'length' property on the server side you may still use Associative Array
  • Else you may keep the simple Array as one of the elements of your Object and send the Object

posted by Arul | link |<prev. | ^top | next> | comments [1]
Tuesday, July 11, 2006

Bug.AMFPHP: Service Browser does not handle method table 'arguments' metadata defined as key value pairs.

While defining the method table for my ObjectStore service I noticed it. Those who use the JavaDoc style comments to generate the method table may never notice this issue.

Arguments metadata can be defined as an array of strings (as created by javadoc comments) or array of array which contains argument name as the key and settings as the value. More on this at amfphp.org

ServiceBroswer class always expects the arguments data as numeric index based array. If you supply key value pair it renders it as 'Array' instead of the actual argument name. Also it does not remember the arguments submitted last time.
Following picture shows the issue

I did the following modifications to '_printMethod' function in ServiceBrowser.php under the 'amfphp/browser' folder to make it work :)

$keyIndex = 0;	
	foreach($arguments as $key => $name) {
			if(is_array($name)){
				$name = $key;
				$key = $keyIndex ++;
			}
			$method .= '<tr class="caption"><td class="key">' . $name . '</td><td><input class="inputbox" type="text" name="' . $methodName . '_arguments[]" maxlength="65535" value="'. htmlspecialchars(strip($_POST[$methodName . "_arguments"][$key])) . '"/></td></tr>'."\n";
}

posted by Arul | link |<prev. | ^top | next> | add comment
Tuesday, July 11, 2006

News.AMFPHP: Introducing ObjectStore.

What is ObjectStore?
Object Store is a service for creating, managing and accessing objects on the server. It is a light weight alternative to keeping XML data on the server.

How do we compare ObjectStore with RemoteSharedObject?
ObjectStore is similar to RemoteSharedObject in terms of storing data on the server, but ObjectStore does not poll (automatically refresh) data and does not fire events on change, although this can be achieved by writing your own Actionscript.

Do we need AMFPHP to use ObjectStore?
AMFPHP is needed only when you need to send and receive the data from flash through remoting, All the data access api is available to PHP.

What are the data types supported by ObjectStore?
following data types are supported

PHP ActionScript
boolean Boolean
integer Number
float/double Number
string String
NULL null
array
(index based)
Array
associate array
(key based)
Object

How do we access data in ObjectStore?
you can access object using a combination of file path and object path, say for example "myfolder/subfolder/myobject.childobject.property" ('/' is used to indicate the folders and '.' is used to indicate the objects) here "myfolder/subfolder/myobject" is the file path and "childobject.property" is the object path.

I'm planning to create a new object, which one should I prefer to use file path or object path?
consider file paths like the name spaces in as2 / package in as3. Use them to avoid name clashes and to organize your objects wisely. object path is the actual object structure which can be compared to properties of the classes in Actionscript. Lengthy object path is going to result in bigger object files on the server, so try to keep it as file path as whenever possible.

Where can I get ObjectStore?
You will be able to download ObjectStore from my blog soon, keep watching this blog for more updates :)

How much it costs?
It will be free for both noncommercial and commercial use.

more info to follow...

posted by Arul | link |<prev. | ^top | next> | add comment
Tuesday, July 04, 2006

Examples.Flash 9: How to load data from a remote URL?

I found that the DataLoadingTest class given in Adobe Labs ActionScript 3 Resources site was buggy and did not work. I've corrected the file myself and made it work. Here is the working code :)
  1. package
  2. {
  3. import flash.net.URLLoader;
  4. import flash.net.URLRequest;
  5. import flash.events.Event;
  6. public class DataLoadingTest
  7. {
  8. private var urlString : String = "http://weblogs.macromedia.com/mxna/";
  9. private var dataLoader : URLLoader;
  10. public function DataLoadingTest ()
  11. {
  12. dataLoader = new URLLoader ();
  13. dataLoader.addEventListener ("complete", onDataLoad);
  14. dataLoader.addEventListener ("securityError", onSecurityError);
  15. dataLoader.load (new URLRequest (urlString));
  16. }
  17. private function onDataLoad (event : Event) : void
  18. {
  19. trace ("Raw Data : " + event.target.data);
  20. }
  21. private function onSecurityError (event : Event) : void
  22. {
  23. trace ("Security Error : " + event);
  24. }
  25. }
  26. }
  27. /*
  28. //Usage:-
  29. //place the following code in the first frame
  30. var dlt:DataLoadingTest=new DataLoadingTest();
  31. */
You can download the file from here.

posted by Arul | link |<prev. | ^top | next> | comments [3]
Tuesday, July 04, 2006

Examples.Flash 9: Porting XMLHighlighter class to ActionScript 3.

XMLHighlighter generates color highlighted pretty printed HTML code for the given XML document, I have ported it from ActionScript 2 to ActionScript 3.

Here is what I learned during the process
  • XML object in ActionScript 3 is different (It is ECMAScript for XML (E4X)).
  • For backward compatibility we have XMLDocument class which is equalent to XML in Actionscript 3.
  • In ActionScript 3 we need to keep the class inside Package container.
I replaced all "XML" to "XMLDocument" from the source, Moved my XMLHighlighter class inside blank Package, renamed it as XMLDocumentHighlighter. That's all.

Here is the resulting class with usage example
  1. /*
  2. ************************************************************
  3. Developed by R.Arul Kumaran [arul@shockwave-india.com] *
  4. for more code keep visiting [www.shockwave-india.com/blog] *
  5. ************************************************************
  6. version 1.0 Last updated on 4 July, 2006
  7. */
  8. /*
  9. XMLHighlighter for ActionScript3 generates color highlighted pretty printed HTML code
  10. */
  11. package
  12. {
  13. import flash.xml.*
  14. class XMLDocumentHighlighter
  15. {
  16. public static var useCDATA : Boolean = true;
  17. //_c: color string list
  18. private static var _c : Object = {
  19. tag : '0000FF', att : 'FF0000', txt : '000000', tgt : '990000'
  20. };
  21. //_fTag: get font begin tag
  22. private static function _fTag (clr : String, content : String)
  23. {
  24. return "<font color='#" + clr + "'>" + content;
  25. }
  26. // _tf: font tag close string
  27. private static var _tf : String = "</font>";
  28. // public function
  29. public static function highlight (x : XMLDocument) : String
  30. {
  31. //var x:XML;
  32. var ignoreWhite = x.ignoreWhite;
  33. var s : String = _fTag (_c.tag, '');
  34. x.ignoreWhite = true;
  35. if (x.nodeName == undefined)
  36. {
  37. if (x.xmlDecl != undefined)
  38. {
  39. s += x.createTextNode (x.xmlDecl) + '\r';
  40. }
  41. if (x.docTypeDecl != undefined)
  42. {
  43. s += x.createTextNode (x.docTypeDecl) + '\r';
  44. }
  45. s += _getHStr (x.firstChild, '', '');
  46. } else
  47. {
  48. s += _getHStr (x, '', '');
  49. }
  50. x.ignoreWhite = ignoreWhite;
  51. return "<pre>" + s + _tf + "</pre>";
  52. }
  53. private static function _getHStr (x, tab : String, r : String) : String
  54. {
  55. var s : String = '';
  56. switch (x.nodeType)
  57. {
  58. //TEXT_NODE
  59. case 3 :
  60. //Is it a CDATA Node?
  61. var xt : String = x.toString ();
  62. if (useCDATA && (x.nodeValue.indexOf ('<') != - 1 || x.nodeValue.indexOf ('>') != - 1))
  63. {
  64. s = "&lt;![CDATA[" + _fTag (_c.txt, '<b>' + xt + '</b>') + _tf + "]]&gt;";
  65. } else
  66. {
  67. s = _fTag (_c.txt, '<b>' + xt.split ('&').join ('&amp;') + '</b>') + _tf;
  68. }
  69. break;
  70. //ELEMENT_NODE
  71. case 1 :
  72. default :
  73. s = r + tab + '&lt;' + _fTag (_c.tgt, x.nodeName) + _tf;
  74. for (var v in x.attributes)
  75. {
  76. s += _fTag (_c.tgt, " " + v) + _tf + "=&quot;" + _fTag (_c.att, x.attributes [v]) + _tf + "&quot;";
  77. }
  78. if (x.firstChild == null)
  79. {
  80. s += "/&gt;";
  81. } else
  82. {
  83. s += "&gt;" + _getHStr (x.firstChild, tab + "\t", "\r");
  84. if (x.lastChild.nodeType == 3)
  85. {
  86. s += "&lt;/";
  87. } else
  88. {
  89. s += '\r' + tab + "&lt;/";
  90. }
  91. s += _fTag (_c.tgt, x.nodeName) + _tf + "&gt;";
  92. }
  93. }
  94. if (x.nextSibling != null)
  95. {
  96. s += _getHStr (x.nextSibling, tab, r);
  97. }
  98. return s;
  99. }
  100. }
  101. }
  102. /*
  103. //Usage:-
  104. //copy this as file to the same folder as your FLA
  105. //Usage Example:
  106. var my_xml:XMLDocument=new XMLDocument('<a><b><c/></b></a>');
  107. trace(XMLDocumentHighlighter.highlight(my_xml));
  108.  
  109. //trace output :
  110.  
  111. <pre><font color='#0000FF'>&lt;<font color='#990000'>a</font>&gt;
  112. &lt;<font color='#990000'>b</font>&gt;
  113. &lt;<font color='#990000'>c</font>/&gt;
  114. &lt;/<font color='#990000'>b</font>&gt;
  115. &lt;/<font color='#990000'>a</font>&gt;</font></pre>
  116.  
  117.  
  118. */
You can download the file from here. I will be writing a XMLHighlighter class which takes advantage of the new E4X XML class.

posted by Arul | link |<prev. | ^top | next> | add comment
Monday, July 03, 2006

Code.PHP: Removing Byte Order Mark (BOM) from the given string.

Since PHP does not recognize and ignore BOM in the loaded files, I wrote the following script to find and remove the BOM from the loaded string.
function removeBOM($str=''){
	if(strpos($str, "»")==1)$str=substr($str, 3);
	return $str;
}
/*
//Usage:-
$text = removeBOM(file_get_contents("myData.xml",true));
*/

posted by Arul | link |<prev. | ^top | next> | add comment

footnote:-
Also check the recent entries and feel free to add your comments. I need your comments to improve this blog