Playing with MouseEvent in Flex 3

November 12, 2008 4 comments

I have come across a very interesting problem while developing a flex application where I have a
button control and I want to call two different functions on  click of the button . The interesting part
is that I want to call two different functions on different events of the same button control, one at
single click and other at double click .
Now what to do in this case as it will always execute the function defined at single click .
So what I am gonna do is to use a Timer using setInterval( ) method and use it to solve this problem.

The code goes here -

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.utils.clearInterval;
private var timeGap:Number = new Number();
private function doubleClick(event:MouseEvent):void {
clearInterval(timeGap);
//put your code here to be executed on double click
Alert.show("double click");
}
private function singleClick(event:MouseEvent):void {
clearInterval(timeGap);
timeGap = setInterval(otherClick, 250);
}
private function otherClick():void {
//put your code here to be executed on single click
Alert.show("first click");
clearInterval(timeGap);
}
]]>

SingleTon Pattern in Flex

November 4, 2008 2 comments

What is singleton pattern?

The singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. If you create the class as a singleton then no way to create more than one instance. But, you can get that single instance in any number of classes. So all the classes will share the same properties and behaviours of that singleton object.

How to implement the singleton pattern?

Implementation of a singleton pattern must satisfy the single instance and global access principles. It requires a mechanism to access the singleton class member without creating a class object and a mechanism to persist the value of class members among class objects. The singleton pattern is implemented by creating a class with a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object. To make sure that the object cannot be instantiated any other way, the constructor is made protected (not private, because reuse and unit test could need to access the constructor). Note the distinction between a simple static instance of a class and a singleton: although a…

Modular Applications

November 4, 2008 No comments yet

Modular applications

Sometimes our flex application’s size becomes very large. Due to this, we are facing many problems such as bandwidth, network traffic and it will take more time to load. We have many ways to solve this problem such as

1. Do not embed the assets into the project.
2. Modules.

About Modules

Modules are the swf files which can be loaded and unloaded dynamically by an application. The user cannot run the modules independently in the browser or the flash player. But the user can share the modules in any number of applications.

Benifits of Modules

  • Smaller initial download size of the SWF file.
  • Shorter load time due to smaller SWF file size.
  • Better encapsulation of related aspects of an application. For example, a “reporting” feature can be separated into a module that you can then work on independently.
  • Any number of applications can share the modules.

Creating the Modules

To create the modules we should create seperate mxml or actionscript class and an application that uses the modules. We can create the modules in two ways, one is by using the mxml and by using the actionscript class.

Creating the modules by using the

Philosophy of Object Oriented Programming and Software Design

November 1, 2008 5 comments

Now, I am no expert in OOP or software design, but here’s a philosophy which might help you make the most of what you know about OOP and software design.

PureMVC

October 28, 2008 1 comment

PureMVC is a framework which helps the Flex programmers to create applications in the MVC architecture. It helps the programmers to develop loosely coupled components. It helps to create the resusable codes. Very easy to understand and maintain than other frameworks. Forces the singleton pattern.

We can divide the pureMVC as:

  • Facade & Core
  • Controller & Commands
  • Model & Proxies
  • View & Mediators
  • Observers & Notifications

Steps to follow in PureMVC

1. Main application should call the facade.startup(this). Here facade is the singletone instance of ApplicationFacade class.

2. ApplicationFacade

  • Singleton class.
  • It extedns the org.puremvc.as3.patterns.facade.Facade.
  • It implements org.puremvc.as3.interfaces.IFacade .
  • Should override the initializeController() method.
  • It defines static constants for Notification names.
  • Initializes the Commands used to access and notify the Commands, Mediators and Proxies.

3. MacroCommand(s)

  • It extends the org.puremvc.as3.patterns.command.MacroCommand.
  • It implements the org.puremvc.as3.interfaces.ICommand.
  • Should override the initializeMacroCommand() method.
  • Executes the SimpleCommands and MacroCommands.
  • User can registerand retrieve the Mediators and Proxies.

4. SimpleCommand(s)

  • It extends the org.puremvc.as3.patterns.command.SimpleCommand.
  • It implements org.puremvc.as3.interfaces.ICommand.
  • Should override the execute( note:INotification ) method.
  • User can register and

RIA and Flex

October 27, 2008 No comments yet

RIA

  • A rich Internet application (RIA) is a Web application designed to deliver the same features and functions normally associated with deskop applications.
  • RIAs typically form a stateful client application with a separate services layer on the backend.
  • Run in a web browser, or do not require software installation
  • Run locally in a secure environment called a sandbox
  • Installation footprint is smaller — overhead for updating and distributing the application is trivial, or significantly reduced compared to a desktop or OS native application
  • Updates/upgrades to new versions can be automatic or transparent to the end user
  • Users can use the application from any computer with an internet connection
  • Many tools exist to allow off-line use of applications, such as Adobe AIR, Google Gears, Curl, and other technologies
  • Most RIA techologies allow the user experience to be consistent, regardless of what operating system the client uses.
  • Web-based applications are generally less prone to viral infection than running an actual executable

Flex

Flex Builder IDE