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]


Thursday, June 29, 2006

Code.Flash MX: Solution for using relative paths in swfs to load data.

Only starting from Flash 9 and Actionscript 3 we can reliably use relative path to load data. Let me explain the problem.

say for example we have an swf file named 'Slide.swf' in a folder 'Slide001' folder which loads 'data.xml' using the following statement
my_xml=new XML();
my_xml.onLoad=function(success){
        //process the xml here
}
my_xml.load('data.xml')
This works fine when we directly call the swf, or the html page that embeds the swf stays in the same folder.

But if you load the swf('Slide.swf') inside another swf which resides in the parent folder, 'data.xml' is expected at the parent folder instead of 'Slide001'

Same happens when we move the html to parent folder. The prototype I've given below, which finds the path of the current swf can solve this problem.
MovieClip.prototype.addProperty('path', function () {
        if (this._path == undefined) {
                var a = this._url.split('/');
                a.pop();
                this._path = a.join('/')+'/';
        }
        return this._path;
}, null);
Once you have the above prototype change the xml.load statement as shown below
my_xml=new XML();
my_xml.onLoad=function(success){
        //process the xml here
}
my_xml.load(this.path+'data.xml')

posted by Arul | link | ^top | next> | comments [9]
Wednesday, June 28, 2006

Examples.MTASC: Using XMLShortcuts Example.

XML Shortcuts helps to access the XMLNodes with ease. You may read my previous post which compares the XMLShortcuts with XPath from XFactor Studio, XML to Object Prototype, and XMLNode easy access by tatsuo kato

Here is a example file, that shows how you can use XMLShortcuts in your MTASC projects.
class XMLShortcutsExample
{
        function XMLShortcutsExample ()
        {
                //Activate the XML Shortcuts
                XMLShortcuts.activate ();
                //Create an XML Object
                //Note: Avoid declaring as XML
                var my_xml = new XML ()
                //ignoreWhite=true is not a must for XML Shortcuts, but it can improve performance
                //for the sake of display we ignore it here
                //_xml.ignoreWhite=true;
                my_xml.onLoad = function (success)
                {
                        if (success)
                        {
                                _root.t1_txt.text += "Original XML:\n" + this;
                                _root.t2_txt.text += "my_xml.english.a = " + my_xml.english.a + "\r\n";
                                _root.t2_txt.text += "my_xml.english.a_1 = " + my_xml.english.a_1 + "\r\n";
                                _root.t2_txt.text += "my_xml.english.$b = " + my_xml.english.$b + "\r\n";
                                _root.t2_txt.text += "my_xml.english.c._word = " + my_xml.english.c._word + "\r\n";
                                _root.t2_txt.text += "my_xml.english.c.__text = " + my_xml.english.c.__text + "\r\n";
                                _root.t2_txt.text += "my_xml.english.a_1.nodeIndex = " + my_xml.english.a_1.nodeIndex + "\r\n";
                                _root.t2_txt.text += "my_xml.english.c.rootNode instanceof XML = " + (my_xml.english.c.rootNode instanceof XML) + "\r\n";
                        }
                }
                //Load the XML
                my_xml.load ("XMLShortcutsExample.xml");
                var tf : TextFormat = new TextFormat ();
                tf.font = "Courier";
                //Create a TextFied to display
                _root.createTextField ("t1_txt", 0, 0, 0, 300, 400);
                _root.t1_txt.text = "XMLShortcutsExample:\n\n";
                _root.t1_txt.setNewTextFormat (tf);
                _root.createTextField ("t2_txt", 1, 300, 0, 500, 400);
                _root.t2_txt.text = "XMLShortcuts Usage:\n\n";
                _root.t2_txt.setNewTextFormat (tf);
                _root.t2_txt.background = true;
                _root.t2_txt.backgroundColor = 0xDDDDDD;
        }
        static function main () : Void
        {
                var app : XMLShortcutsExample = new XMLShortcutsExample ();
        }
}
above script produces the swf below, when compiled using the following command
mtasc "XMLShortcutsExample.as" -swf "XMLShortcutsExample.swf" -frame 1 -header 800:400:12:FFFFFF -main

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

Extension.Flash MX: XML Shortcuts V2.2 MTASC Edition released.

Now XMLShortcuts meets MTASC :)

I received many requests to make XMLShortcuts available for MTASC (Motion Twin Action Script Compiler). I could not do it with my busy schedule so far, but finally here it is
Download package consists of XMLShortcuts.as, an example and help files



You can download it from here

posted by Arul | link |<prev. | ^top | next> | add comment
Wednesday, June 14, 2006

Code.Flash MX: String.isWhite and String.getWordCount().

This is the same word count function that I showed in the previous post presented in the good old way of adding more properties and methods through the prototype.

String object is extened to have isWhite read only property and getWordCount method.
String.prototype.addProperty('isWhite', function () {
        return !isNaN(this+' 0');
}, null);

/*Usage Example:-

var str = " \t \r";
trace(str.isWhite);
//traces true

str+=".";
trace(str.isWhite);
//traces false

*/
String.prototype.getWordCount = function() {
        if (this.isWhite) {
                return 0;
        }
        var arr = this.split(' ');
        var l = arr.length;
        for (i in arr) {
                if (arr[i].isWhite) {
                        l--;
                }
        }
        return l;
};
/*Usage Example:-

var str = "World   is  \r  Not Enough. ";
trace(str.getWordCount());
//traces 4
*/

posted by Arul | link |<prev. | ^top | next> | add comment
Wednesday, June 14, 2006

Code.Flash MX: Counting number of words in a String.

Here is a simple code to get the word count. To ease up the process, I do not count the words that are not separated by space
For Example "Mr.Arul" will still be counted as one word. but it makes sure whitespace is not counted as words
Here is the code
function wordcount(txt) {
        if (!isNaN(txt+" 0")) {
                return 0;
        }
        var arr = txt.split(' ');
        var l = arr.length;
        for (var i in arr) {
                if (!isNaN(arr[i]+" 0")) {
                        l--;
                }
        }
        return l;
}

/*Usage Example:-

trace(wordcount("I  Love Flash      "));
//traces 3

*/

posted by Arul | link |<prev. | ^top | next> | comments [1]
Saturday, June 10, 2006

Examples.Flash Lite: Generating Unique Random Number for Flash Lite 1 and 1.1.

Generating Unique random number for Flash Lite 1.1 is tricky because of the Flash 4 style syntax. I've made a sample application which shows how this can be achieved.

Here is the SWF showcasing this

You can download the FLA from here

posted by Arul | link |<prev. | ^top | next> | add comment
Saturday, June 10, 2006

Tips.Flash MX: Easy way to Randomize an Array.

Here is the sample code to shuffle the contents of an array
// Here is a simple function for randomizing the array
function randomsort(a, b) {
        return Math.random()>.5 ? -1 : 1;
}
//usage example
var arr = [1, 2, 3, 4, 5];
arr.sort(randomsort);
trace(arr);
//traces 4,3,1,5,2

posted by Arul | link |<prev. | ^top | next> | add comment
Wednesday, June 07, 2006

Tips.Flash MX: including Actionscript 1 files in Actionscript 2 Project.

When we are including an AS1 file in an Fla which has to be published as AS2, we need to be careful in naming the include file. There shouldn't be any object initialized in _global which has the same name as the include file.

Say for example,

I had a include file called Security.As and inside that had _global.Security=new Object(). When I published I got the following error
**Error** C:\Documents and Settings\areal\Desktop\Security.As: Line 1: ActionScript 2.0 class scripts may only define class or interface constructs.
     Security=new Object();

Total ActionScript Errors: 1   Reported Errors: 1

To resolve this issue we need to rename the Security.as file to something else, for example SecuritySystem.as and change the include statement accordingly

posted by Arul | link |<prev. | ^top | next> | comments [1]
Saturday, June 03, 2006

Tips.Flash MX: Is Running in Flash IDE?

When testing my application in IDE, I wanted to use some hard coded test data instead of Every time loading the dynamic data. System.capabilities.isDebugger is the boolean property which is true when we are testing in IDE or special Debug Player.

Here is the sample code that I've used
if (!System.capabilities.isDebugger) {
        _myxml.load(xmlPath+"?"+"policynumber="+policynumber+"&PolyType="+PolyType+"&strSelectAgentCode="+strSelectAgentCode+"&strCountryCode="+strCountryCode+"&policyStatus="+policyStatus+"&AgncyCde="+AgncyCde+"&passinagency="+passinagency);
} else {
        _myxml.load("xml/table.xml");
}

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