Labs

It works in my machine!

Archive for 2009

AS3 Dumper

without comments

i just found at libspark this handy class
it’s just like the ObjectDumper Class from AS2 =D
and has the ability to throw the message to the firebug console =D

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package org.libspark.utils 
{
    import flash.external.ExternalInterface;
    import flash.utils.getQualifiedClassName;
 
    /**
     * <p>Data????????????perl?Data::Dumper???????
     * ???????????Object, Array, Number, String, Boolean???
     * XML?????????????????
     * ??????FireBug?console???????????????????????
     * debug, info, warn, error ???????????????</p>
     * <listing>
     * package {
     *    import org.libspark.utils.Dumper;
     *    public Class Hoge {
     *        var test:Object = { a:'hoge', b:'fuga'};
     *        Dumper.debug(test);
     *        trace(Dumper.toString(test));
     *    }
     *    // output
     *         $var0 = {
     *                     'a' => 'hoge',
     *                     'b' => 'fuga',
     *                 }
     *     
     * }</listing>
     * @author dealforest
     * @version 0.102
     */
 
    public class Dumper {
 
        private static const INDENT:String = "    ";
        /*
         * @default 4tab
        */
        private static var _dumpString:String = "";
 
        /**
         * ????????????????????
         *
         * @param args ???????(????)
         * @return _txt ??????????????????
         */
        public static function toString(... args):String {
            var _txt:String = _dumpString = '';
            for (var a:String in args)
                _txt += parse(args[a]);
            return _txt;
        }
 
        /**
         * FireBug???????'debug'?????
         *
         * @param args ???????(????)
         */
        public static function debug(... args):void {
            if (!ExternalInterface.available) return;
 
            var _txt:String = _dumpString = '';
            for (var a:String in args)
                _txt += parse(args[a]);
            //interim action for IE
            ExternalInterface.call('function (txt) { try { console.log(txt); } catch (e) {}; }', _txt);
        }
 
        /**
         * FireBug???????'info'?????
         *
         * @param args ???????(????)
         */
        public static function info(... args):void {
            if (!ExternalInterface.available) return;
 
            var _txt:String = _dumpString = '';
            for (var a:String in args)
                _txt += parse(args[a]);
            //interim action for IE
            ExternalInterface.call('function (txt) { try { console.info(txt); } catch (e) {}; }', _txt);
        }
 
        /**
         * FireBug???????'warn'?????
         *
         * @param args ???????(????)
         */
        public static function warn(... args):void {
            if (!ExternalInterface.available) return;
 
            var _txt:String = _dumpString = '';
            for (var a:String in args)
                _txt += parse(args[a]);
            //interim action for IE
            ExternalInterface.call('function (txt) { try { console.warn(txt); } catch (e) {}; }', _txt);
        }
 
        /**
         * FireBug???????'error'?????
         *
         * @param arg ???????(????)
         */
        public static function error(... args):void {
            if (!ExternalInterface.available) return;
 
            var _txt:String = _dumpString = '';
            for (var a:String in args)
                _txt += parse(args[a]);
            //interim action for IE
            ExternalInterface.call('function (txt) { try { console.error(txt); } catch (e) {}; }', _txt);
        }
 
        /**
         * ????????????????????
         *
         * @param arg ???????(??????1?)
         * @return ?????????????
         * @private
         */
        public static function parse(arg:*):String {
            var argIndent:String = ('$var'+ ' = ');
            _dumpString += argIndent;
            inspect(arg, argIndent.replace(/./g, ' '));
            _dumpString += '\n';
           return _dumpString;
        }
 
        /**
         * ?????????????????????
         *
         * @param arg ???????(??????1?)
         * @param indent ????????
         * @private
         */
        private static function inspect(arg:*, indent:String):void {
            var bracket:Object;
 
            switch (getQualifiedClassName(arg)) {
                case 'Object':
                    bracket = {start: '{', end: '}'};
                case 'Array':
                    bracket ||= {start: '[', end: ']'};
                    _dumpString += bracket.start + '\n';
                    recursion(arg, indent + INDENT);
                    _dumpString += (indent +bracket.end);
                    break;
                default:
                    _dumpString += format(arg, indent, true);
            }
        }
 
        /**
         * ?????????????????
         *
         * @param arg ???????(??????1?)
         * @param indent ????????
         * @private
         */
        private static function recursion(arg:*, indent:String):void {
            for (var index:String in arg) {
                var tmp:* = arg[index];
                var className:String = getQualifiedClassName(tmp);
                var bracket:Object;
 
                switch(className) {
                    case 'Object':
                        bracket = {start: '{', end: '}'};
                    case 'Array':
                        bracket ||= {start: '[', end: ']'};
                        var str:String = (getQualifiedClassName(arg) == 'Object')
                            ? '\'' + index + '\' => ' : '';
                        var indent_str:String = str.replace(/./g, ' ');
 
                        _dumpString += (indent + str + bracket.start + "\n");
                        recursion(tmp, indent + indent_str + INDENT);
                        _dumpString += (indent + indent_str + bracket.end + ",");
                        break;
                    default:
                        _dumpString += format(tmp, indent, false, arg, index);
                }
                _dumpString += "\n";
            }
        }
 
        /**
         * ??????????????????
         *
         * @param target ?????Object
         * @param indent ????????
         * @param braket ,??????????
         * @param parent ?????Object
         * @param index Object?key
         * @return ???????????????
         * @private
         */
        private static function format(target:Object, indent:String, bracket:Boolean, parent:* = null, index:String = null):String {
            var className:String = getQualifiedClassName(target);
            var str:String = "";
 
            if (getQualifiedClassName(parent) == 'Object')
                return indent +  "\'" + index + "\'" + " => " + target + (bracket ? '' : ',');
 
            switch (className) {
                case 'String':
                    return (bracket)
                        ? "\'" + target + "\'"
                        : indent + "\'" + target + "\',";
 
                case 'Array':
                case 'int':
                case 'uint':
                case 'Number':
                case 'Boolean':
                    return (bracket)
                        ? target.toString()
                        : indent + target.toString() + ",";
                default:
                    return 'don\'t analyze';
            }
        }
    }
}

from Dumper Class

check it out libspark.org they have very interesting things in their repository

by the way, the japanese characters doesn’t display in my browser =(

Written by Raúl

May 5th, 2009 at 2:13 pm

Posted in General

Random Points inside a Triangle

without comments

just copy and paste the following code:

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
 
function getRandomPointInTriangle (A:Point,B:Point,C:Point):Point {
 
	//P = aA + bB + cC
	//@see http://www.cgafaq.info/wiki/Random_Point_In_Triangle
 
	var a:Number = Math.random();
	var b:Number = Math.random();
 
	if (a + b > 1) {
		a = 1-a;
		b = 1-b;
	}
 
	var c:Number = 1-a-b;
 
	var rndX:Number = (a*A.x)+(b*B.x)+(c*C.x);
	var rndY:Number = (a*A.y)+(b*B.y)+(c*C.y);
 
	return new Point(rndX,rndY);
}
 
 
var triangleHeight:uint = 150;
var triangleShape:Shape = new Shape();
triangleShape.graphics.lineStyle(1,0xff0000);
triangleShape.graphics.moveTo(triangleHeight/2, 5);
triangleShape.graphics.lineTo(triangleHeight, triangleHeight+5);
triangleShape.graphics.lineTo(0, triangleHeight+5);
triangleShape.graphics.lineTo(triangleHeight/2, 5);
addChild(triangleShape);
 
 
var p1:Point = new Point(triangleHeight/2, 5);
var p2:Point = new Point(triangleHeight, triangleHeight+5);
var p3:Point = new Point(0, triangleHeight+5);
 
//
//
//
//
 
var source:BitmapData = new BitmapData(triangleHeight,triangleHeight,true,0);
var bitmap:Bitmap = new Bitmap(source);
 
var sprite:Sprite = new Sprite();
sprite.addChild(bitmap);
addChild(sprite);
 
 
source.fillRect(source.rect,0);
source.lock();
 
for (var i:int = 0;i<50;i++) {
	var p:Point = getRandomPointInTriangle(p1,p2,p3);
	source.setPixel32(p.x,p.y,0xffff0000);
}
 
source.unlock();

Cheers!

Written by Raúl

May 5th, 2009 at 1:50 pm

Posted in AS3

Always on Top

with one comment

today i found my self trying to put an Sprite on the top of the display list
so here is the basic idea for solve that problem

1
2
3
4
5
6
7
8
9
10
11
 
function alwaysOnTop_handler(e:Event):void {
	//make this child always on top!
	parent.addChild(this);
}
 
function added_handler(e:Event):void {
	parent.addEventListener(Event.ADDED, alwaysOnTop_handler, false, 0, true);
}
 
addEventListener(Event.ADDED_TO_STAGE, added_handler, false, 0, true)

cheers!

Written by Raúl

April 21st, 2009 at 5:24 pm

Posted in AS3, General

Tagged with

Grupo W @ badFonts group [ Flash CS4 text properties issue ]

with 3 comments

Using the Flash CS4 i had a little problem… everytime i tried to use the text tool, either flash crashed after or before even putting the text box on stage.

Thinking it was a flash bug i google search it… i found this.

i read only a few top posts and found that the issue was the computer performance, but then David here at W has the same computer as me. After formatting my pc flash was running ok, so there, problem fixed!

BUT when i put all of my stuff back in, again flash was doing the same thing. After a few hairs pulled and desks banged, we discover that it was the fonts i installed in the pc the day before, and going back to the link i found , reading all of the posts, Raúl found that same solution posted there.

What did we learn from this?
1: you don’t need to install every font you find.
2: read a little more before taking actions with the first post you find XD so you don’t have to format your computer in vain. XD

Written by wolf

April 8th, 2009 at 6:49 pm

Posted in General

Tagged with , , ,

Validating a String

without comments

well this is a handy code snippet to validate a string
if you want to avoid some bad words, this is for you:

1
2
3
4
5
6
7
8
9
10
11
12
 
function isValid(str:String):Boolean {
        var regExp:RegExp = /\b(badword|nastyWord)\b/i;
	var _isValid:Boolean = !regExp.test(str);
        return _isValid;
}
 
var _inValidMessage = "this is a example for a bad badword it's really nasty";
var _validMessage = "Hello Word!";
 
trace(isValid(_inValidMessage)) //false
trace(isValid(_validMessage))//true

you can add more words just separating them by a pipeline ( | ) in the Regular Expression

Cheers.

Written by Raúl

April 6th, 2009 at 4:27 pm

Posted in AS3, General

Tagged with

wowFlag [flarToolkit + pv3d + wowEngine]

with 7 comments


wowFlag from Wolf on Vimeo.

As promised on youtube: here it’s the source

( thx to saqoosha for the help on the flarToolkit issue of translating the flag fixed vertex… you can find his example of doing this on his site, but he maded it for away3d =) )

the code is very extended, so if you have any doubts post them here, we will try and answer all of them :)

Written by wolf

March 4th, 2009 at 3:27 pm

Command Pattern [Part 1]

with 5 comments

Well this is i think the most common pattern that i use in my apps
it’s not the exact implementation but it works for me =D

here’s and example on how i use it
Read the rest of this entry »

Written by Raúl

March 3rd, 2009 at 4:48 pm

Posted in General

HttpFox

with one comment

i was looking something like the “Activity” Window in Safari for Firefox and found this handy extension HttpFox

it comes very useful when you want to track your content-page information

cheers!.

Written by Raúl

January 26th, 2009 at 1:34 pm

Posted in General

busy busy busy!

without comments

hi guys! well we’ve been busy these days, in fact some of us didn’t have vacations these holidays
so you can imagine the load of work that we have
we promise to post some interesting things just in a couples of days (or weeks =D hehe)

meanwhile you can visit our new blog http://blog.grupow.com

cheers!

Written by Raúl

January 12th, 2009 at 3:03 pm

Posted in General