Showing posts with label flex. Show all posts
Showing posts with label flex. Show all posts

Saturday, February 11, 2012

Illustrator: adobe illustrator CS5.5 training notes

Illustrator is vector graphics drawing tool while Photoshop is pixel graphic drawing tool.

Resolution measurements:
DPI = Dot Per Inch
PPI = Pixel Per Inch

Resolution types:
When you create a picture 1" X 1" with PPI = 1000px then this is called high resolution document, but if the same image size created with PPI = 10px then this called low resolution image.

What is vector Graphics?

Vector Graphics is the use of geometrical primitives such as points, lines, curves, and shapes or polygon(s), which are all based on mathematical equations, to represent image in computer graphics.

Illustrator uses anchor points and connects these anchors with lines called paths, which is re-calculated each time image is sized.

when drawing in illustrator the path connecting anchor points doesn't appears on final appearance of drown shape, it just a skeleton for the graphic shape while appearance is the glow of the shape.

Tuesday, December 13, 2011

Flex: Random numbers

Every now and then you need to do something at random in your application (i.e. pick a random item from a collection).

For that, you probably need some random number to decide which option to choose. Here is a simple example that shows you how to generate random numbers in Flex.

To do this, you can you can use the static method random() in the Math class. Math.random gives you a random number between 0 and 1. 

To get a whole random number between, for example 0 and 100, just multiply the Math.random() result by 100 and round the outcome of that calculation.

Source code for the example:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" baseColor="0xCCCCFF"
               xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    
    <fx:Script>
        <![CDATA[
            
            private function generateRandomNumber( start:Number, end:Number ):void
            {
                var randomNum:Number;
                if( end == 1 )
                {
                    // Number is between 0 and 1, don't round.
                    randomNum = Math.random();
                }
                else{
                    // Number is between 0 and 100 or 1000, round the number
                    randomNum = Math.round( Math.random() * end );
                }
                // Show random number in TextInput
                randomNumber.text = randomNum.toString();
            }
            
        ]]>
    </fx:Script>
    
    <s:layout>
        <s:VerticalLayout paddingLeft="5" paddingRight="5"
                          paddingTop="5" paddingBottom="5" />
    </s:layout>
    
    
    <s:VGroup id="hgroup">
        <s:Button label="Number between 0 and 1" 
                  click="generateRandomNumber(0,1)" width="250"/>
        <s:Button label="Number between 0 and 100" 
                  click="generateRandomNumber(0,100)" width="250"/>
        <s:Button label="Number between 0 and 1000" 
                  click="generateRandomNumber(0,1000)" width="250"/>
    </s:VGroup>
    <s:TextInput id="randomNumber" width="{hgroup.width}" editable="false"
                 textAlign="center" height="60" fontSize="20" 
                 fontWeight="bold"/>
</s:Application>

Saturday, December 10, 2011

Flex: A Timer API


Let’s say you want something to happen in your application every once in a while automatically. The Timer class is the way to do it. I was already familiar with the Timer class from Java, the Flex one isn’t all that different. Let’s create a simple exmple, just switching an image every XX seconds.

First, set up your layout, we only need an image, declare it using MXML:

<mx:Image width="1024" height="768"/>
</code>

//Now we need some variable to store the current image URL in, 
// make it a private var in your script section:
[cc lang="actionscript"]
<mx:Script>
    <![CDATA[
            
    [Bindable]
    private var currentImageUrl:String = 
            "<image path>/image1.jpg";
    ]]>
</mx:Script>

OK, with that done we need that Timer to that we talked about, let’s create an initialize method that creates a Timer with a delay of five seconds (5000 milliseconds) and starts the timer:

private function init():void{
                
    var timer:Timer = new Timer(5000);
    timer.addEventListener(TimerEvent.TIMER, switchImage);
    timer.start();
} 

Add it to the initialize event in the application tag:

<mx:Application initialize="init()" 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute"> 

Notice that I added an event listener to the timer variable before starting it. This event listener is called every time the Timer reaches five seconds, let’s implement the event listener:

private function switchImage(event:TimerEvent):void{
                
    if(currentImageUrl == 
            "<image path>/image1.jpg")
    {
        currentImageUrl = 
            "<image path>/image2.jpg";
    }
    else
    {
        currentImageUrl = 
            "<image path>/image1.jpg";
    }          
}

This example is simple, it just checks whether the current image is image1 and switches it to image2 if it is. If it isn’t, the current image must be image2 so image1 has to be shown.

So now you have a basic understanding of the Timer class, it’s very useful sometimes!

Full application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application initialize="init()" xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="absolute" viewSourceURL="srcview/index.html">
    <mx:Script>
        <![CDATA[
            []
            private var currentImageUrl:String = "<path>/image1.jpg";
            
            private function init():void{
                
                var timer:Timer = new Timer(5000);
                timer.addEventListener(TimerEvent.TIMER, switchImage);
                timer.start();
                
            }
            private function switchImage(event:TimerEvent):void{
                
                if(currentImageUrl == "<path>/image1.jpg"){
                   currentImageUrl = "<path>/image2.jpg";
                }
                else{
                    currentImageUrl = "<path>/image1.jpg";
                }
            }
        ]]>
    </mx:Script>
    <mx:Image source="{currentImageUrl}" width="1024" height="768"/>
</mx:Application>