Archive for June, 2009

Top 10 Free Resources for Background Patterns and Textures for Web Designers

Posted in Uncategorized on June 28th, 2009 by admin – Comments Off

Quite often we stumble on to a blog that looks bland, in dire need of some color, a little bit of character, these sites maybe aren’t very familiar with blog design, let alone CSS. The simplest way to freshen up a site is with a new theme or to do a little CSS tweaking with your current theme. You could be surprised with the results. In this article I will show you the best resources for backgrounds and textures.

go to full blog post

ActionScript 3. Resources

Posted in actionscript 3 on June 22nd, 2009 by admin – Comments Off

Hi here is resources of ActionScript 3 libraries.

From Adobe Labs

The Adobe Developer Rel

ations team is releasing a set of free and open ActionScript 3.0 APIs to help developers get started building Flex 2.0 applications. These libraries are of beta quality and we have released them as-is under this license. Adobe does not support them.

  1. corelib
  2. FlexUnit
  3. Flickr
  4. Mappr
  5. RSS and Atom libraries
  6. Odeo
  7. YouTube

Parse RSS character class

Posted in actionscript 3 on June 16th, 2009 by admin – Comments Off

Hi, this is class that I user when I have to parse RSS or XML data. I use it because there are several character that appear like &#NN and I use in this case escapeASCIICharacters.

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.stanislavstankov.shared.api {
   
    import flash.xml.XMLDocument;
    import flash.xml.XMLNode;
   
    public final class ParseUtils {
       
       
        public static function escapeFotDB($value_:String):String {
            var regTest:RegExp;
            regTest = /&/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&/g, "&");
            }
            regTest = /'/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/'/g, "'");
            }
            regTest = /"/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/"/g, '"');
            }
            regTest = /</;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/</g, "&lt;");
            }
            regTest = />/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/>/g, "&gt;");
            }
            return $value_;
        }
       
        public static function escapeXMLCharacters($value_:String):String {
            var regTest:RegExp;
            regTest = /&amp;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&amp;/g, "&");
            }
            regTest = /&apos;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&apos;/g, "'");
            }
            regTest = /&quot;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&quot;/g, '"');
            }
            regTest = /&lt;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&lt;/g, "<");
            }
            regTest = /&gt;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&gt;/g, ">");
            }
            return $value_;
        }
       
        public static function escapeASCIICharacters($value_:String):String {
            var regTest:RegExp;
            regTest = /\n/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/\n/g, " ");
            }
            $value_ = $value_.replace(/[ ]{2,}/g, " ");
           
            regTest = /&#38;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#38;/g, "&");
            }
            regTest = /&#038;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#038;/g, "&");
            }
            regTest = /&#x2018;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#x2018;/g, '"');
            }
            regTest = /&#39;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#39;/g, "'");
            }
            regTest = /&#039;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#039;/g, "'");
            }
            regTest = /&#8217;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#8217;/g, "'");
            }
            regTest = /&#8216;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#8216;/g, "'");
            }
            regTest = /&#x2018;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#x2018;/g, '"');
            }
            regTest = /&#x2019;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#x2019;/g, '"');
            }
            regTest = /&#34;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#34;/g, '"');
            }
            regTest = /&#60;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#60;/g, "<");
            }
            regTest = /&#62;/;
            if (regTest.test($value_)) {
                $value_ = $value_.replace(/&#62;/g, ">");
            }
            return $value_;
        }
       
        public static function allEscapes($value_:String):String {
            return escapeASCIICharacters(escapeXMLCharacters($value_));
        }
       
       
    }
}

Flash: TextCreator

Posted in actionscript 3 on June 16th, 2009 by admin – Comments Off

This is class that with which you can create TextField in couple of lines:

1
2
3
4
5
6
7
var text1_txt:TextField = TextCreator.createTextField(TextCreator.FONT_MYRIADPRO_12, 0x0, 11, true, 0, true);
//var text1_txt:TextField= TextCreator.createTextField(TextCreator.FONT_MYRIADPRO_12, 0xffffff, 11, true, -0.3, true, TextCreator.TFA_CENTER);
//var text1_txt:TextField= TextCreator.createTextField(TextCreator.FONT_MYRIADPRO_12, 0x565656, 11);
text1_txt.text = "text1";
text1_txt.x = 93;
text1_txt.y = 20;
addChild(text1_txt);

You have to keep in mind that VerdanaEmbedded and MyRiadPro12Embedded are extended Font classes in package com.stanislavstankov.fonts Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
package com.stanislavstankov.fonts {
    import flash.text.Font;
   
    public final class MyRiadPro12Embedded extends Font {
       
        /*------------------------------------
            Constructor
        ------------------------------------*/

        public function MyRiadPro12Embedded():void {
        }
       
    }
}

Text Creator 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
81
82
83
84
85
86
87
88
package com.stanislavstankov.utils {
    import com.stanislavstankov.fonts.*;
   
    import flash.text.AntiAliasType;
    import flash.text.Font;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;
   
    public final class TextCreator {
       
        public static const FONT_VERDANA:int = 1;
        public static const FONT_MYRIADPRO_12:int = 2;
       
        /**
         * Constant; centers the text in the text field.
         *  Use the syntax TextFormatAlign.CENTER.
         */

        public static const TFA_CENTER:String = "center";
        /**
         * Constant; justifies text within the text field.
         *  Use the syntax TextFormatAlign.JUSTIFY.
         */

        public static const TFA_JUSTIFY:String = "justify";
        /**
         * Constant; aligns text to the left within the text field.
         *  Use the syntax TextFormatAlign.LEFT.
         */

        public static const TFA_LEFT:String = "left";
        /**
         * Constant; aligns text to the right within the text field.
         *  Use the syntax TextFormatAlign.RIGHT.
         */

        public static const TFA_RIGHT:String = "right";
       
        public static function createTextField(font_:int, color_:int, size_:int, kerning_:Boolean = true, letterSpacing_:Number = 0, bold_:Boolean = false, align_:String = TFA_LEFT):TextField {
            var textformat:TextFormat = new TextFormat();
            textformat.align = align_;
            textformat.color = color_;
            textformat.bold = bold_;
            textformat.font = getFont(font_).fontName;
            textformat.size = size_;
            textformat.kerning = kerning_;
            textformat.letterSpacing = letterSpacing_;
           
            var textfield:TextField = new TextField();
            textfield.antiAliasType = AntiAliasType.ADVANCED;
            textfield.embedFonts = textfield.cacheAsBitmap = true;
            textfield.selectable = textfield.mouseEnabled = textfield.mouseWheelEnabled = false;
            textfield.defaultTextFormat = textformat;
            textfield.autoSize = TextFieldAutoSize.LEFT;
            return textfield;
        }
       
       
        private static function getFont($fontID_:int):Font {
            var font:Font;
            switch ($fontID_) {
                case FONT_VERDANA:
                    font = new VerdanaEmbedded();
                break;
                case FONT_MYRIADPRO_12:
                    font = new MyRiadPro12Embedded();
                break;
            }
            return font;
        }
       
        public static function noMoreLine($txt_:TextField, $fromLine_:int, $suffix_:String = "..."):void {
            var imax:int = $txt_.numLines - $fromLine_;
            //added !!! on 28!
            $txt_.height = $txt_.textHeight + $fromLine_ * 2;
            if (imax < 1) {
                return void;
            }
            var numSymb:int = 0;
            for (var i:int = i; i < imax; i++) {
                numSymb += $txt_.getLineLength(i + $fromLine_);
            }
            var txt:String = $txt_.text;
            $txt_.text = txt.substr(0, txt.length - numSymb - $suffix_.length) + $suffix_;
            $txt_.height = $txt_.textHeight + $fromLine_ * 2;
        }
       
    }
}

AS3: Bitmap Functions

Posted in actionscript 3 on June 16th, 2009 by admin – Comments Off

Hi to all,
this is one class that I used in all my projects, where I need bitmap resizing.
Class main purpoise is to help you with resizing images, when you load them. It have only one public static function resize.
You pass there bitmap image, the width you want, the height you want and the type of resizing.
Hope it helps you :)

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
81
82
83
84
85
86
87
88
89
90
91
92
package com.stanislavstankov.shared.utils {
   
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.DisplayObject;
    import flash.geom.Matrix;
    import flash.display.PixelSnapping;
   
    public final class BitmapFunctions {
       
        /**
         * Specifies that the image be visible in the specified area without distortion while maintaining the original aspect ratio of it.
         */

        public static const SHOW_ALL:String = "showAll";
       
        /**
         * Specifies that the image be visible in the specified area without distortion but possibly with some cropping, while maintaining the original aspect ratio of the application.
         */

        public static const NO_BORDER:String = "noBorder";
       
        /**
         * Specifies that the image be visible in the specified area without trying to preserve the original aspect ratio.
         */

        public static const EXACT_FIT:String = "exactFit";
       
       
        public static function resize(image_:Bitmap, width_:int, height_:int, type_:String = BitmapFunctions.EXACT_FIT):Bitmap {
            var outBitmap:Bitmap;
           
            var bitmapData:BitmapData = new BitmapData(image_.width, image_.height, false);
            bitmapData.draw(image_);
            switch (type_ ) {
                case EXACT_FIT:
                    bitmapData = resizeBitmapData(bitmapData, width_, height_);
                    outBitmap = new Bitmap(bitmapData, PixelSnapping.AUTO, true);
                break;
                case SHOW_ALL:
                    if ((image_.width < 2) || (image_.height < 2)) {
                        return null;
                    }
                    if ((image_.width <= width_) && (image_.height <= height_)) {
                        outBitmap = image_;
                    } else {
                        var propToHeight:Number = height_ / image_.height;
                        var propToWidth:Number = width_ / image_.width;
                        var beW:int;
                        var beH:int;
                       
                        if (propToWidth  > propToHeight) {
                            beW = image_.width * propToHeight;
                            beH = image_.height * propToHeight;
                        } else {
                            beW = image_.width * propToWidth;
                            beH = image_.height * propToWidth;
                        }
                        bitmapData = resizeBitmapData(bitmapData, beW, beH);
                        outBitmap = new Bitmap(bitmapData, PixelSnapping.AUTO, true);
                    }
                break;
                case NO_BORDER:
                    var nbpropToHeight:Number = height_ / image_.height;
                    var nbpropToWidth:Number = width_ / image_.width;
                    var nbbeW:int;
                    var nbbeH:int;
                   
                    if (nbpropToWidth  < nbpropToHeight) {
                        nbbeW = image_.width * nbpropToHeight;
                        nbbeH = image_.height * nbpropToHeight;
                    } else {
                        nbbeW = image_.width * nbpropToWidth;
                        nbbeH = image_.height * nbpropToWidth;
                    }
                    bitmapData = resizeBitmapData(bitmapData, nbbeW, nbbeH);
                    outBitmap = new Bitmap(bitmapData, PixelSnapping.AUTO, true);
                break;
            }
            return outBitmap;
        }
       
        private static function resizeBitmapData(bmpSource:BitmapData, setWidth:Number, setHeight:Number):BitmapData {
            var scaleWidth:Number = setWidth / bmpSource.width;
            var scaleHeight:Number = setHeight / bmpSource.height;
            var bmp:BitmapData = new BitmapData (setWidth, setHeight, true, 0);
            var matrix:Matrix = new Matrix ();
            matrix.scale(scaleWidth, scaleHeight);
            bmp.draw(bmpSource, matrix);
            return bmp;
        }
       
    }
   
}

Flash: Simple flash banner

Posted in actionscript 3, example on June 16th, 2009 by admin – Comments Off

hi, I’m posting link to flash banner code because of numerous requests of link to my scripting style. :)

billboard flash banner

billboard flash banner

here is the zip file of source files

Flash: Strange Error>> ArgumentError: Error #2025:

Posted in actionscript 3 on June 16th, 2009 by admin – Comments Off

This strange error was thrown at me when developing one object can load many images. Sometimes it have to load new image while still not load the old one. So this is what I get from time to time.

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::Loader/flash.display:Loader::_load()
at flash.display::Loader/load()

The fix was to use Loader.unload(), every time you want to use Loader.contentLoaderInfo.content to put it in different Sprite.

I suggest you to read this topic about the problem:

Failure to Unload: Flash Player 9′s Dirty Secret from gSkinner blog

Line and Symbol Counter

Posted in Uncategorized on June 16th, 2009 by admin – Comments Off

hi I want to share gadjet that friend working on C# made for me :)
It is called “Line and Symbol Counter”. The idea is to count lines and symbols of your code. Here are print screen.

Lines and Sybols counter

Lines and Sybols counter

Thsi is what it looks like when you start it :) It get automaticly the directory that you are in. It catch all sub level folders and open all files with the extension written into File Filter. So when you user it here what you will get:

lines and symbols counter - result

lines and symbols counter - result

So lets explain results:
Code: is all lines that are not comments or blank or only tabs.
Comment: is all lines that have comment into it. Commets are “//“, “/*“, “/**“. If you have code and comment into one line it will count as comment :/
Blank: this is lines that have only /t or intervals into it.
All lines: This is hard to be guest. Sum all :)

P.S.
Line and Symbol Counter.exe
Here is the the software it is a simple EXE.

Flash: How to prevent pop-up blocking in Firefox

Posted in AS3 optimization, actionscript 3 on June 16th, 2009 by admin – Comments Off

Hi, I just want to point out some class that I find very useful. It help you no to block FF pop, when you call navigateToURL method. So here is the link:

Problems using navigateToURL

Here I will post the actionscript file, because when you copy it from the location it copies you also the numbers, which is kind of annoying.

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.stanislavstankov.utils {
   
    import flash.external.ExternalInterface;
    import flash.net.URLRequest;
    import flash.net.navigateToURL;
   
    /**
     * Collection of URL util functions.
     *
     * ActionScript 3.0 / Flash 9
     *
     * @package    com.apdevblog.utils
     * @author     Philipp Kyeck / phil@apdevblog.com
     * @copyright  2008 apdevblog.com
     * @version    SVN: $Id: URLUtils.as 19 2008-04-08 09:57:50Z phil $
     *
     * based on script by
     * @author Sergey Kovalyov
     * @see http://skovalyov.blogspot.com/2007/01/how-to-prevent-pop-up-blocking-in.html
     *
     * and based on script by
     *
     * @author Jason the Saj
     * @see http://thesaj.wordpress.com/2008/02/12/the-nightmare-that-is-_blank-part-ii-help
     */

   
    public final class URLUtils {
       
       
       
        protected static const WINDOW_OPEN_FUNCTION:String = "window.open";
       
        /*------------------------------------
            Constructor
        ------------------------------------*/

        public function URLUtils():void {
        }
        /*------------------------------------
            Public methods
        ------------------------------------*/

       
       
        /**
         * Open a new browser window and prevent browser from blocking it.
         *
         * @param url        url to be opened
         * @param window     window target
         * @param features   additional features for window.open function
         */

       
        public static function openWindow(url:String, window:String = "_blank", features:String = ""):void {
            var browserName:String = getBrowserName();
            if (getBrowserName() == "Firefox") {
                ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features);
            } else if (browserName == "IE") {
                ExternalInterface.call("function setWMWindow() {window.open('" + url + "');}");
            } else if (browserName == "Safari") {
                navigateToURL(new URLRequest(url), window);
            } else if (browserName == "Opera") {
                navigateToURL(new URLRequest(url), window);
            } else {
                //Otherwise, use Flash's native 'navigateToURL()' function to pop-window.
                //This is necessary because Safari 3 no longer works with the above ExternalInterface work-a-round.
                navigateToURL(new URLRequest(url), window);
            }
        }
       
       
       
       
        /*------------------------------------
            Private methods
        ------------------------------------*/

        /**
         * return current browser name.
         */

         private static function getBrowserName():String {
             var browser:String;
             //Uses external interface to reach out to browser and grab browser useragent info.
             var browserAgent:String = ExternalInterface.call("function getBrowser(){return navigator.userAgent;}");
             //Determines brand of browser using a find index. If not found indexOf returns (-1).
             if (browserAgent != null && browserAgent.indexOf("Firefox") >= 0) {
                browser = "Firefox";
            } else if (browserAgent != null && browserAgent.indexOf("Safari") >= 0) {
                browser = "Safari";
            } else if (browserAgent != null && browserAgent.indexOf("MSIE") >= 0) {
                browser = "IE";
            } else if (browserAgent != null && browserAgent.indexOf("Opera") >= 0) {
                browser = "Opera";
            } else {
                browser = "Undefined";
            }
            return (browser);
        }
       
       
    }
}

I do not pretend in any way of that I write or have part of writing this class. Only distributing it :)

Array Function Class

Posted in AS3 optimization, actionscript 3 on June 16th, 2009 by admin – Comments Off

This is class that I used often in my works :) Hope you find it useful. It manipulates Array Object. It is user to add or remove element from a certain position.

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
package com.stanislavstankov.shared.utils {
   
    public final class ArrayFunction {
       
        /*------------------------------------
            Public methods
        ------------------------------------*/

        /**
         * Remove element from an array.
         * @param selectedArr Array from whom will be remove element;
         * @param elementIndex Removed index from array. Firts item is with index = 0;
         * @return New array with removed element;
        */

        public static function removeElement(selectedArr:Array, elementIndex:int):Array {
            var outArr:Array = [];
            outArr = outArr.concat(selectedArr.slice(0, elementIndex), selectedArr.slice(elementIndex + 1));
            return outArr;
        }
       
        /**
         * Add element at index position in array. If given elementIndex is bigger or equal of the lenght of array, element is added like last element
         * @param selectedArr Array from whom will be remove element;
         * @param elementIndex Removed index from array. Firts item is with index = 0;
         * @param newObj Object that will be added;
         * @return New array with removed element;
        */

        public static function addElement(selectedArr:Array, elementIndex:int, newObj:Object):Array {
            var outArr:Array = [];
            outArr = outArr.concat(selectedArr.slice(0, elementIndex), newObj, selectedArr.slice(elementIndex));
            return outArr;
        }
       
    }
}