Posts from the ‘Flash / Actionscript’ Category

Flash Word Counter

1 CommentSeptember 9 | 2009

Here’s a little app I developed in Adobe Flash that generates list of word occurrences for any given text. To use it,  just copy and paste the text into the input field, click submit and the results will be displayed in a table which you then can copy the data into excel or wordpad.

I’m hoping to develop this further in the future so that its able to generate some interesting visualisations based on the results.

Please leave a comment if you have any ideas for improvement or notice any bugs.

AS3: Random Colour between 2 colour values

Leave a commentJuly 22 | 2009

Useful little snippet to generate a colour between 2 colour values in ActionScript 3

1
2
3
4
5
6
7
8
9
10
11
12
13
import fl.motion.Color;

var color1:uint = 0x03e338;
var color2:uint = 0xbbe303;
var newColor:uint = Color.interpolateColor(color1, color2, randomHue);

private function _randomNumber(low:Number=NaN, high:Number=NaN):Number
{
    var low:Number = low;
    var high:Number = high;

    return Math.random() * (high - low) + low;
}

Simple AS3 dynamic fonts class

1 CommentMay 26 | 2009

Simple class to include dynamic fonts in your flash movie. You can either compile this from your fav AS editor or apply it to an FLA as the document class.

To access the fonts, all you will need to is load in the generated swf into your project and use the fontName value you specify in the class to apply the appropriate font.

It’s also good practice to limit the unicode range to characters you need. Adobe provides a good reference, flash-unicode-table.xml, which you can find inside the Flex SDK 2/frameworks folder.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package {
   
    import flash.display.MovieClip;
    import flash.text.Font;
   
    public class Fonts extends MovieClip {
        [Embed(source='C:/WINNT/fonts/DiCnBd.ttf', fontName='_dinBold', unicodeRange='U+0021-U+007A,U+00BB,U+00A9,U+2122,U+00AE')]  
        public static var _dinBold:Class;
        Font.registerFont(_dinBold);
        trace("_dinBold LOADED");
       
        [Embed(source='C:/WINNT/fonts/arial.ttf',fontName='_Arial', unicodeRange='U+0021-U+007A,U+00BB,U+00A9,U+2122,U+00AE')]  
        public static var _Arial:Class;
        Font.registerFont(_Arial);
        trace("_Arial LOADED");
       
        [Embed(source='C:/WINNT/fonts/arialbd.ttf', fontWeight= "bold",fontName='_ArialBold', unicodeRange='U+0021-U+007A,U+00BB,U+00A9,U+2122,U+00AE')]  
        public static var _ArialBold:Class;
        Font.registerFont(_ArialBold);
        trace("_ArialBold LOADED");
       
    }
}

Simple way to randomise Arrays in AS3

Leave a commentApril 21 | 2009

Found this over at daveoncode and thought i would like to share it:

1
2
3
4
5
6
7
8
9
10
private function _getRandom(arr:Array):void

    var arr2:Array = new Array();

    while (arr.length > 0) {
        arr2.push(arr.splice(Math.round(Math.random() * (arr.length - 1)), 1)[0]);
    }

    return arr2;
}

INSTABUDGET09 launched

1 CommentApril 20 | 2009

UPDATE: The interactive has now recieved more than 10k submission in the first week. Its amazing, never reaching that amount only in the first week.

Our new budget simulator game for news.com.au is now available to play at http://www.news.com.au/instabudget/.

I was the front-end developer for the project using AS3 and implementing the  MVC  pattern for the build and other little bits and pieces. It was my first attempt to using mvc, and I must say it wasn’t as complicated as I thought it would be, even though I probably made some mistakes here and there.

instabudget

Snippet: Easy globalToLocal in AS3

2 CommentsApril 7 | 2009

Short little snippet I found the other day to convert coordinates from one movieclip to another in Actionscript 3

1
2
3
4
5
6
function localToLocal(fr:MovieClip, to:MovieClip):Point {
    return to.globalToLocal(fr.localToGlobal(new Point()));
};

//Useage
var localPoint:Point = localToLocal(fromMc,toMc);

AS3 Currency Formatter

16 CommentsMarch 26 | 2009

Here’s a little class I created to convert any number into currency format, which allows specification of decimal places and currency symbol.

Download the Currency Formatter AS3 class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Use:
 *
 * import agi.utils.Format
 *
 * var _format:Format =  new Format();
 *
 * trace out:
 * trace(_format.currency(32783.2397,2,$)); //$32,783.24
 * trace(_format.currency(32783.2397,3,$)); //$32,783.240
 * trace(_format.currency(32783.2397,2,"")); //32,783.24
 *
 */

package agi.utils
{
    public class Format
    {
        //-----------CONSTRUCTOR-----------//
        public function Format() { }
       
        //-----------PRIVATE METHODS-----------//
        public function currency(num:Number,decimalPlace:Number=2,currency:String="$"):String
        {
            //assigns true boolean value to neg in number less than 0
            var neg:Boolean = (num < 0);
           
            //make the number positive for easy conversion
            num = Math.abs(num)

            var roundedAmount:String = String(num.toFixed(decimalPlace));
           
            //split string into array for dollars and cents
            var amountArray:Array = roundedAmount.split(".");
            var dollars:String = amountArray[0]
            var cents:String = amountArray[1]
           
            //create dollar amount
            var dollarFinal:String = ""
            var i:int = 0
            for (i; i < dollars.length; i++)
            {
                if (i > 0 && (i % 3 == 0 ))
                {
                    dollarFinal = "," + dollarFinal;
                }
               
                dollarFinal = dollars.substr( -i -1, 1) + dollarFinal;
            }  
           
            //create Cents amount and zeros if necessary
            var centsFinal:String = String(cents);
           
            var missingZeros:int = decimalPlace - centsFinal.length;
       
            if (centsFinal.length < decimalPlace)
            {
                for (var j:int = 0; j < missingZeros; j++)
                {
                    centsFinal += "0";
                }
            }
           
            var finalString:String = ""

            if (neg)
            {
                finalString = "-"+currency + dollarFinal
            } else
            {
                finalString = currency + dollarFinal
            }

            if(decimalPlace > 0)
            {
                finalString += "." + centsFinal;
            }
           
            return finalString;
        }
    }
}

GreenSock Tweening Platform v11 Beta

Leave a commentMarch 23 | 2009

http://blog.greensock.com/v11beta/

The team over at Greensock not content with their latest release of awesomeness that is known as tweenmax/lite are hard at work on the next update v11 which is now in beta with major changes to the guts of the code and introduction of new features such as TimelineLite and TimelineMax.

TimelineLite and TimelineMax classes that originated from TweenGroup feature:

  • add labels, play(), stop(), gotoAndPlay(), gotoAndStop(), restart(), and even reverse()!
  • nest timelines within timelines as deeply as you want. When you pause or change the timeScale of a timeline, it affects all of its descendents.
  • populate the timeline and build sequences easily using append(), prepend(), insert(), and insertMultiple() methods.
  • speed up or slow down the entire timeline with its timeScale property. You can even tween this property to gradually speed up or slow down the timeline.
  • reverse() smoothly anytime
  • and lots more.

Visit http://www.greensock.com/as/docs/tween/ for the full AS documention.

Full Screen Flash AS2 Gallery v3

13 CommentsMarch 22 | 2009

Moved this post over from ideaography.net since i will be combining the 2 blogs into 1.  I kind of like the domain name still so im not sure if i’m going to keep it or not.

20-12-08 update:

  • updated image navigation to include info button and now can be placed either top or bottom
  • seperated MainImage and Thumb into individual classes
  • updated to the lates tweenmax with tweengroup
  • minor updates to code

Some of the new features in this version include:

  • Auto generated album menu, that can be configured in the XML file. It also has a built in function that removes the menu when there is only 1 album
  • Moved a majority of the settings to the XML file for easier updates
  • Addressed ratio sizing on the full screen image
  • Included a flash version 8 fla file (sorry for not including that before)
  • And some code improvements to make it run smoother.

Demos:

Download Full Screen AS2 Flash Gallery

Thanks to everyone who provided feedback and comments on the previous versions as it helped to identify the features that were missing and the issues that needed fixing. Keep the comments coming on this new version as well and let me know if you find any bugs or features that you want added.