Archive for the ‘ Development ’ Category

Ultra-light jQuery calendar

New concept for date selection jquery calendar.

Autor Blog: http://roberto.open-lab.com/2010/04/06/ultra-light-jquery-calendar/
Download page: http://bugsvoice.com/applications/bugsVoice/site/test/calendarPickerDemo.jsp
Download: Ultra-light jQuery calendar

AS3 Condicional Switch Stament

Imagine we can use switch staments with conditional operators other then strict equality.

This way we can do a code like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var value:int = 2;
switch(value){
    case < 1:
        trace("Value is less than 1");
        break;
    case 2:
        trace("Value definitely equals 2");
        break;
    case >= 3:
        trace("Value is greater than or equal to 3");
        break;
    case > 1 && < 3:
        trace("Value is greater than 3 and less than 5");
        break;
    case !== 5:
        trace("Value definitely doesn't equal 5");
        break;
}

Navigating the web I have find one solution:

1
2
3
4
5
6
7
8
9
10
11
12
var value:int = 2;
switch (true) {
    case value < 1:
        trace("Value is less than 1");
    break;
    case value == 1:
        trace("Value equals 1");
    break;
    case value > 1:
        trace("Value is greater than 1");
    break;
}

Dynamically create instance of Vector class

AS3 don’t let us dynamically create an instance of class Vector with elements of various types, the solution is use getDefinitionByName.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package
{
    import flash.system.ApplicationDomain;
    import flash.utils.getQualifiedClassName;  

    public class ClassUtils
    {
        static private const  VECTOR_CLASS_NAME : String = getQualifiedClassName( Vector );

        static public function getVectorDefinition(itemDefinition : Class, applicationDomain : ApplicationDomain = null) : Class
        {
            if(!applicationDomain) applicationDomain = ApplicationDomain.currentDomain;
            return applicationDomain.getDefinition( VECTOR_CLASS_NAME + '.<' + getQualifiedClassName( itemDefinition ) + '>' ) as Class;
        }      
        static public function createCustomVector(itemDefinition : Class, length : uint = 0, fixed : Boolean = false, applicationDomain : ApplicationDomain = null) : Vector.<*>
        {
            var definition : Class = getVectorDefinition( itemDefinition, applicationDomain );
            return new definition( length, fixed );
        }      
    }
}

To get definition of Vector class with specified item type:

1
2
3
4
var itemType:Class = Sprite;
var definition:Class = ClassUtils.getVectorDefinition(itemType);
trace(definition); // [class Vector.<flash.display::Sprite>]
trace(getQualifiedClassName(definition)); // __AS3__.vec::Vector.<flash.display::Sprite>

To create Vector class instance with specified item type:

1
2
3
var itemType:Class = Sprite;
var vector:Vector.<*> = ClassUtils.createCustomVector(itemType);
trace(getQualifiedClassName(vector)); // __AS3__.vec::Vector.<flash.display::Sprite>