Gunjan’s Weblog

Share your knowledge in Flash and Flex

Cairngorm July 10, 2009

Filed under: Cairngorm, Flex — gunjank @ 8:08 pm
Tags: , , , ,
 

Flex events August 6, 2008

Filed under: Flex — gunjank @ 5:11 am
Tags: , , , ,

About events

This section introduces you to the event model in Flex 2. In addition, this section describes the Event object and its subclasses, and describes the event dispatching model. For a quick start in using events in Flex, you can skip this section and see sample code in Using events.

Events let a developer know when something happens within a Flex application. They can be generated by user devices, such as the mouse and keyboard, or other external input, such as the return of a web service call. Events are also triggered when changes happen in the appearance or life cycle of a component, such as the creation or destruction of a component or when the component is resized.

Any user interaction with your application can generate events. Events can also occur without any direct user interaction, such as when data finishes loading from a server or when an attached camera becomes active. You can “listen” for these events in your code by adding an event listener. Event listeners are the functions or methods that you write to respond to specific events. They are also sometimes referred to as event handlers.

The Flex event model is based on the Document Object Model (DOM) Level 3 Events Model. Although Flex does not adhere specifically to the Document Object Model standard, the implementations are very similar.

Components generate and dispatch events and consume (listen to) other events. An object that requires information about another object’s events registers a listener with that object. When an event occurs, the object dispatches the event to all registered listeners by calling a function that was requested during registration. To receive multiple events from the same object, you must register your listener for each event.

Components have built-in events that you can handle in ActionScript blocks in your MXML applications. You can also take advantage of the Flex event system’s dispatcher-listener model to define your own event listeners outside of your applications, and define which methods of your custom listeners will listen to certain events. You can register listeners with the target object so that when the target object dispatches an event, the listeners get called.

All visual objects, including Flex controls and containers, are subclasses of the DisplayObject class. They are in a tree of visible objects that make up your application. The root of the tree is the Stage. Below that is the SystemManager object, and then the Application object. Child containers and components are leaf nodes of the tree. That tree is known as the display list. An object on the display list is analogous to a node in the DOM hierarchical structure. The terms display list object and node are used interchangeably in this topic.

http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000462.html

 

Actionscript versions January 15, 2008

ActionScript version

2000–2003: ActionScript “1.0″ With the release of Flash 5 in September 2000, the “actions” from Flash 4 were enhanced once more and named “ActionScript” for the first time.[2] This was the first version of ActionScript with influences from JavaScript and the ECMA-262 (Third Edition) standard, supporting the said standard’s object model and many of its core data types. Local variables may be declared with the var statement, and user-defined functions with parameter passing and return values can also be created. Notably, ActionScript could now also be typed with a text editor rather than being assembled by choosing actions from drop-down lists and dialog box controls. With the next release of its authoring tool, Flash MX, and its corresponding player, Flash Player 6, the language remained essentially unchanged; there were only minor changes, such as the addition of the switch statement and the “strict equality” (===) operator, which brought it closer to being ECMA-262-compliant. Two important features of ActionScript that distinguish it from later versions are its loose type system and its reliance on prototype-based inheritance. Loose typing refers to the ability of a variable to hold any type of data. This allows for rapid script development and is particularly well-suited for small-scale scripting projects. Prototype-based inheritance is the ActionScript 1.0 mechanism for code reuse and object-oriented programming. Instead of a class keyword that defines common characteristics of a class, ActionScript 1.0 uses a special object that serves as a “prototype” for a class of objects. All common characteristics of a class are defined in the class’s prototype object and every instance of that class contains a link to that prototype object.

2003–2006: ActionScript 2.0 The next major revision of the language, ActionScript 2.0, was introduced in September 2003 with the release of Flash MX 2004 and its corresponding player, Flash Player 7. In response to user demand for a language better equipped for larger and more complex applications, ActionScript 2.0 featured compile-time type checking and class-based syntax, such as the keywords class and extends. (While this allowed for a more flexible object-oriented programming approach, the code would still be compiled to ActionScript 1.0 bytecode, allowing it to be used on the preceding Flash Player 6 as well. In other words, the class-based inheritance syntax was a layer on top of the existing prototype-based system.) With ActionScript 2.0, developers could constrain variables to a specific type by adding a type annotation so that type mismatch errors could be found at compile-time. ActionScript 2.0 also introduced class-based inheritance syntax so that developers could create classes and interfaces, much as they would in class-based languages such as Java and C++. This version conformed partially to the ECMAScript Fourth Edition draft specification.

2006–today: ActionScript 3.0 In June 2006, ActionScript 3.0 debuted with Adobe Flex 2.0 and its corresponding player, Flash Player 9. ActionScript 3.0 was a fundamental restructuring of the language, so much so that it uses an entirely different virtual machine. Flash Player 9 contains two virtual machines, AVM1 for code written in ActionScript 1.0 and 2.0, and AVM2 for content written in ActionScript 3.0. ActionScript 3.0 provides not only a significant enhancement in performance, but also a more robust programming model that lends itself to complex Rich Internet Application development.

The update to the language introduced several new features:

 

Flash players — an overview January 15, 2008

  • Flash Lite 1.0: Flash Lite is the Flash technology specifically developed for mobile phones and consumer electronics devices. Supports Flash 4 ActionScript.
  • Flash Lite 1.1: Added support for some Flash 5 ActionScript.
  • Flash Lite 2.0 and 2.1: Added support for Flash 7 ActionScript 2.0.
  • Flash Lite 3: Added FLV video playback.
  • Flash Player 2: The first version with scripting support. Actions included gotoAndPlay, gotoAndStop, nextFrame and nextScene for timeline control.
  • Flash Player 3: Expanded basic scripting support with the ability to load external SWFs (loadMovie).
  • Flash Player 4: First player with a full scripting implementation (called Actions). The scripting was a slash based syntax and contained support for loops, conditionals, variables and other basic language constructs.
  • Flash Player 6: Added an event handling model, accessibility controls and support for switch. The first version with support for the AMF and RTMP protocols which allowed for ondemand audio/video streaming.
  • Flash Player 8: Further extended ActionScript 1/2 by adding new class libraries with APIs for controlling bitmap data at run-time, file uploads and live filters for blur and dropshadow.
  • Flash Player 9 (initially called 8.5): Added ActionScript 3.0 with the advent of a new virtual machine, called AVM2 (ActionScript Virtual Machine 2), which coexists with the previous AVM1 needed to support legacy content. Performance increases were a major objective for this release of the player including a new JIT compilation. Support for binary sockets, E4X XML parsing, full-screen mode and Regular Expressions were added. This is the first release of the player to be titled Adobe Flash Player.
 

actionscript 3.0 — data types January 15, 2008

Data types

ActionScript primarily consists of “fundamental” or “simple” data types which are used to create other data types. These data types are very similar to Java data types. Since ActionScript 3 was a complete rewrite of ActionScript 2, the data types and their inheritances have changed

ActionScript 2 top level data types

  • String – A list of characters such as “Hello World”
  • Number – Any Numeric value
  • Boolean – A simple binary storage that can only be “true” or “false”.
  • Object – Object is the data type all complex data types inherit from. It allows for the grouping of methods, functions, parameters, and other objects.

ActionScript 2 complex data types

There are additional “complex” data types. These are more processor and memory intensive and consist of many “simple” data types. For AS2, some these data types are:

  • MovieClip – An ActionScript creation that allows easy usage of visible objects.
  • TextField – A simple dynamic or input text field. Inherits the Movieclip type.
  • Button – A simple button with 4 frames (states): Up, Over, Down and Hit. Inherits the MovieClip type.
  • Date – Allows access to information about a specific point in time.
  • Array – Allows linear storage of data.
  • XML – An XML object
  • XMLNode – An XML node
  • LoadVars – A Load Variables object allows for the storing and send of HTTP POST and HTTP GET variables
  • Sound
  • NetStream
  • NetConnection
  • MovieClipLoader
  • EventListener

ActionScript 3 top level data types (see Data type descriptions)

  • Boolean – The Boolean data type has only two possible values: true and false. No other values are valid.
  • int – The int data type is a 32-bit integer between -2,147,483,648 and 2,147,483,647.
  • Null – The Null data type contains only one value, null. This is the default value for the String data type and all classes that define complex data types, including the Object class.
  • Number – The Number data type can represent integers, unsigned integers, and floating-point numbers. The Number data type uses the 64-bit double-precision format as specified by the IEEE Standard for Binary Floating-Point Arithmetic (IEEE-754).
  • String – The String data type represents a sequence of 16-bit characters. Strings are stored internally as Unicode characters, using the UTF-16 format. Previous versions of flash used the UTF-8 format.
  • uint – The uint (Unsigned Integer) data type is a 32-bit unsigned integer between 0 and 4,294,967,295.
  • void – The void data type contains only one value, undefined. In previous versions of ActionScript, undefined was the default value for instances of the Object class. In ActionScript 3.0, the default value for Object instances is null.

ActionScript 3 complex data types (see Data type descriptions)

  • Object – The Object data type is defined by the Object class. The Object class serves as the base class for all class definitions in ActionScript.
  • Array – Contains a list of data. Though ActionScript 3 is a strongly-typed language, it does not support typed Arrays. Thus the contents of an Array may be of any type.
  • Date
  • Error
  • Function
  • RegExp
  • XML
  • XMLList
 

Actionscript 3.0 an overview January 15, 2008

Filed under: Flash, Flex, Ria, actionscript — gunjank @ 5:28 am
Tags: , , , , , ,

ActionScript is a scripting language based on ECMAScript (Javascript), used primarily for the development of websites and software using the Adobe Flash Player platform (in the form of SWF files embedded into Web pages). Originally developed by Macromedia, the language is now owned by Adobe (which acquired Macromedia in 2005) which continues its development. ActionScript was initially designed for controlling simple 2D vector animations made in Adobe Flash (formerly Macromedia Flash). Later versions added functionality allowing for the creation of Web-based games and rich Internet applications with streaming media (such as video and audio).

Syntax

ActionScript code is free form and thus may be created with whichever amount or style of whitespace that the author desires. The basic syntax is similar to the C++ programming language.

ActionScript 3.0

ActionScript 3.0 has a similar syntax to ActionScript 2.0 but different set of APIs for creating objects.

var greet:* = addChild(new TextField());
greet.text = "Hello world";

Minimal ActionScript 3.0 programs may be somewhat larger and more complicated due to the increased separation of the programming language and the Flash IDE.

Presume the following file to be Greeter.as:

package com.example
{
        import flash.text.TextField;
        import flash.display.Sprite;

        public class Greeter extends Sprite
        {
                public function Greeter()
                {
                        var txtHello:TextField = new TextField();
                        txtHello.text = "Hello World";
                        addChild(txtHello);
                }
        }
}

Finally, an example of using ActionScript when developing Flex applications, again presuming the following content to be in a file named Greeter.as:

package
{
        public class Greeter
        {
                public static function sayHello():String
                {
                        var greet:String = "Hello, world!";
                        return greet;
                }
        }
}

This code will work with the following MXML application file:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="vertical" creationComplete="initApp()">

        <mx:Script>
                <![CDATA[[
                      public function initApp():void
                      {
                              // Prints our "Hello, world!" message into "mainTxt".
                              mainTxt.text = Greeter.sayHello();
                      }
              ]]>
        </mx:Script>

        <mx:Label id="title" fontSize="24" fontStyle="bold" text="\"Hello, world!\" Example"/>
        <mx:TextArea id = "mainTxt" width="250"/>   

</mx:Application>

ActionScript 3.0 examples

This Hello World example uses ActionScript 3.0:

package
{
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.filters.DropShadowFilter;

        public class HelloWorld2 extends Sprite
        {
                public function HelloWorld2()
                {
                        var shad:DropShadowFilter = new DropShadowFilter (2, 45, 0x000000, 25, 3, 3, 2, 2);
                        var txt:TextField = new TextField();
                        txt.textColor = 0xFFFFFF;
                        txt.filters = [shad];
                        txt.width = 200;
                        txt.x = Math.random() * 300;
                        txt.y = Math.random() * 300;
                        txt.selectable = false;
                        txt.text = "Hello World welcome! [" + Math.round(txt.x) + "," + Math.round(txt.y) + "]";
                        addChild(txt);
                }
        }
}
 

Adobe Flex an overview January 14, 2008

Filed under: Flex, Ria — gunjank @ 4:23 am
Tags: , , , ,

Adobe Flex is a collection of technologies released by Adobe Systems for the development and deployment of cross platform, rich Internet applications based on the proprietary Adobe Flash platform. The initial release in March 2004 by Macromedia included a software development kit, an IDE, and a J2EE integration application known as Flex Data Services. Since Adobe acquired Macromedia in 2005, subsequent releases of Flex no longer require a license for Flex Data Services, which has become a separate product rebranded as LiveCycle Data Services.

In April 2007, Adobe announced plans to open source the Flex 3 SDK. Adobe Flash Player, the runtime on which Flex applications are viewed, and Flex Builder, the IDE used to build Flex applications, remain proprietary and commercial.

Overview

Traditional application programmers found it challenging to adapt to the animation metaphor upon which the Flash Platform was originally designed. Flex seeks to minimize this problem by providing a workflow and programming model that is familiar to these developers. MXML, an XML-based markup language, offers a way to quickly build and layout graphic user interfaces. Interactivity is achieved through the use of ActionScript, the core language of Flash Player that is based on the ECMAScript standard.

The Flex SDK comes with a set of user interface components including buttons, list boxes, trees, data grids, several text controls, and various layout containers. Charts and graphs are available as an add-on. Other features like web services, drag and drop, modal dialogs, animation effects, application states, form validation, and other interactions round out the application framework.

In a multi-tiered model, Flex applications serve as the presentation tier. Unlike page-based HTML applications, Flex applications provide a stateful client where significant changes to the view don’t require loading a new page. Similarly, Flex and Flash Player provide many useful ways to send and load data to and from server-side components without requiring the client to reload the view. Though this functionality offered advantages over HTML and JavaScript development in the past, the increased support for XMLHttpRequest in major browsers has made asynchronous data loading a common practice in HTML-based development too.

Technologies that are commonly compared to Flex include OpenLaszlo, Ajax, XUL, JavaFX and Windows Presentation Foundation .

Adobe Flex 3

On April 26, 2007 Adobe announced their intent to release the Flex 3 SDK under the terms of the open source Mozilla Public License.

Adobe released the first beta of Flex 3, codenamed Moxie, in June 2007. Major enhancements include integration with the new versions of Adobe’s Creative Suite products, support for AIR (Adobe’s new desktop application runtime), and the addition of profiling and refactoring tools to the Flex Builder IDE.

In October 2007, Adobe released the second beta of Flex 3.
On December 12, 2007, Adobe released the third beta of Flex 3.

LiveCycle Data Services

Main article: Flex Data Services

LiveCycle Data Services (previously called Flex Data Services) is a server-side complement to the main Flex SDK and Flex Builder IDE and is part of a family of server-based products available from Adobe. Deployed as a Java EE application, LiveCycle Data Services adds the following capabilities to Flex applications:

  • Remoting, which allows Flex client applications to invoke methods on Java server objects directly. Similar to Java remote method invocation (RMI), remoting handles data marshalling automatically and uses a binary data transfer format.
  • Messaging, which provides the “publish” end of the “publish/subscribe” design pattern. The Flash client can publish events to a topic defined on the server, subscribe to events broadcast from the message service. One of the common use cases for this is real-time streaming of data, such as financial data or system status information.
  • Data management services, which provides a programming model for automatically managing data sets that have been downloaded to the Flex client. Once data is loaded from the server, changes are automatically tracked and can be synchronized with the server at the request of the application. Clients are also notified if changes to the data set are made on the server.
  • PDF document generation, providing APIs for generating PDF documents by merging client data or graphics with templates stored on the server.

Source — http://en.wikipedia.org/wiki/Adobe_Flex

 

Rich Internet Applications (RIA) Landscape/Flex January 8, 2008

Filed under: Flex, Ria — gunjank @ 6:05 am
Tags: , , , ,

Courtsey– Jon Rose’s Blog

When it comes to Rich Internet Applications (RIA), I am way behind to some, and way too far out there for others… Oh well!

It is time to completely embrace the RIA model and put to bed the old Request/Response type model of building web applications. My conclusion is simple, no longer do we have to train our customers to be disappointed with the final product when purchasing online software. The tools are finally good enough to give our business stakeholders and users the ‘rich’ applications they have been asking our industry to build for all these years.

Until recently, I have avoided the ‘Rich Internet Applications’/’Web 2.0’ craze, mostly because I saw Ajax as the primary method available to Java developers, like myself, for enhancing web based applications. I am finally ready to get onboard, but I am still uncomfortable with using the Ajax techniques on a large scale.

In this post, I am asserting the underlying assumption that the majority of the online user interface work going forward will be done in a Client Server like model over the Internet (e.g. Ajax and the like). As far as I am concerned, debate around the question of continuing to use JSF and Struts like frameworks is pretty much over, and any further discussion is for someone else’s blog. We should all be excited that we finally have better ways to build online applications. For me, it has been about finding a method that will enhance the user’s experience, but not be a complete pain to me as a developer.

Going forward, my personal platform of choice for building online user interfaces will be Adobe Flex. Adobe’s recent 2.0 release of Flex finally gives developers a robust solution for building ‘real’ applications and delivering them over HTTP through a browser.

 

I think Flex is cool and you can clearly build ‘sexy’ applications using it, but really who cares? I see way better reasons to utilize the Flex 2 framework as a Java developer:

  1. Of most importance, Flex provides the ability to dramatically improve the end user’s experience, build complex features with ease, and improve productivity (of both the programmer and end user).
  2. Tools:
    1. It builds on the tools Java developers already know.
      1. Eclipse IDE Plug-in.
      2. Ant build tasks for command line and automated builds.
      3. Flex and/or Granite Data Services used for easy Java integration, which deploy to a J2EE Servlet container.
  1. Runtime:
    1. Everyone computer already has the Flash Player and users are used to interacting with Flash based content.
      1. This does matter!!! Overtime it will matter less, but it takes time for users to adopt a new runtime, and as we all saw with Applets it can end up being difficult to get a consistent runtime installed to the masses.
      2. Flash movies run inside a browser and allow for integration with other web technologies (e.g. HTML, CSS, Javascript).
  1. Framework:
    1. A framework 100% geared toward user interfaces.
    2. ActionScript 3.0 is Object Oriented.
    3. The language’s heavy Java influences are obvious.
  2. Seeing is believing… Spend some time looking at some of the sample applications at http://www.flex.org/showcase/.

 

I have been getting a bit of push back when I suggest Flex/Flash as a viable option for building user interfaces to other Java developers. Some of the more common questions/comments are below:

  • ‘Doesn’t Flex cost money?’
    • Adobe does charge for the Flex Builder IDE ($599) and Flex Data Services (FDS) deployed beyond a single CPU. However, you can build and deploy an entire Flex application for FREE. The SDK is free and there are Ant Tasks for creating a build. For the applications I am building, I have concluded that the only paid tool I need is the IDE. Granite Data Services (http://www.graniteds.org/) and Open Source alternative to FDS has met my needs to this point. In addition, Flex also provides methods for integrating with Web Services.
  • ‘I tried developing applications in Flash before, and it just doesn’t seem geared toward developers.’
    • I share this experience, and had the same apprehension about Flex. The key thing about Flex is that it is a framework geared toward application developers, not designers. Although the applications are deployed as Flash movies, little-to-no knowledge is needed of traditional frame-by-frame like Flash development.
  • ‘Wow. Flash, really? That sounds like a really heavyweight method of building applications.’
    • Not to oversimplify, but I have come to view the Flash Player as just another browser when building and deploying Flex applications, except the Flash Player displays consistently across all supported Operating Systems.

 

If you are willing to embrace the Ajax-like model for building web applications there are a number of options to consider in addition to Adobe Flex: Microsoft SilverLight, Open Laszlo, Java FX, and the many Ajax frameworks. Below is a brief review of each of these from my perspective as a Java developer.

 

Ajax

My depth of knowledge on Ajax is limited, as I have avoided using it on any large scale to this point. I do know there are many developers out there with successful deployments of online applications that incorporate significant amounts of Ajax functionality. For me, it just seems to push the standard browser functionality beyond its natural capabilities. Regardless, by its nature, it is always going to be painful for the developer, as they have to support deployment to multiple runtimes and the many cross-platform issues that arise from that.

 

I do believe Ajax, along with HTML, CSS, JavaScript and server side technologies, will always be some part of any comprehensive online application. The only question that still intrigues me is, what parts should they make up?

 

Microsoft SilverLight

I would anticipate SilverLight being the strongest competitor to Flex in the near-and-long-term. As much as I love to hate the Evil Empire, we all know they will commit to making this a world class development platform that integrates with all of their other tools. It appears to already have stronger video support than Flex, and will surely catch Flex in other areas very quickly.

 

My biggest reservation with SilverLight comes strictly as a Java developer. It doesn’t seem to make a lot of sense to learn a new tool set (e.g. Microsoft Visual Studio) and be outside the mainstream trying to integrate Java and SilverLight when there are comparable technologies that are much closer to the Java space. That’s not to say a .NET developer shouldn’t consider Flex, but hey, I don’t know how things work on that side of the software planet.

 

OpenLazslo

OpenLazslo is similar to Flex, as it is an Open Source Framework for building applications that deploy as Flash movies. However, it is my understanding that the current release of the OpenLazslo Framework does NOT target the Flash Player 9 virtual machine (and its many performance benefits). Flash Player 9 was a virtual rewrite with many improvements including support for ActionScript 3.0 and much improved performance (up-to 10 times faster than previous versions according to Adobe). The Flash Player 9 actually ships with two virtual machines for backwards capability (Flash 8 & 9).

 

Regardless of the performance trade-offs, it is still attractive to some because it is an Open Source project. However, Abode committed to Open Sourcing the Flex framework in recent weeks. So, I am not sure that is still a compelling motivation to choice Lazslo over Flex.

 

Java FX

Java FX is a complete joke to me! It’s just another grand Java One announcement with NO release date… and foggy details on what it will look like when it is released. The most promising descriptions describe an Applet like deployment (over the samples that run in Java Web Start outside the browser), which just isn’t going to cut it. Thanks Sun… Thanks for showing us the raw work going on in your R&D labs (more Jon Rose skepticism run amok).

 

The only interesting thing about Java FX is that it is essentially Sun’s acknowledgement that the industry has already shifted away from server side user interface frameworks (e.g. Struts, JSF), in favor of richer client side runtimes.

 

Summary

Each of us comes to our own conclusions on how to best build online applications. For me, Flex is clearly the way to go. As a few wise developers have said to me, ‘Flex is just another tool.’ To a large extent I agree, but the difference to me is that the end product produced from Flex is such a large leap forward when compared with the current landscape.

 

 

References:

http://www.adobe.com/aboutadobe/pressroom/pressreleases/pdfs/200606/062806Flash9.pdf

http://msdn2.microsoft.com/en-us/library/bb428859.aspx

http://www.openlaszlo.org/front_page

http://www.jamesward.org

 

Flex :-Simple and easy August 18, 2007

Filed under: Flex — gunjank @ 5:45 am

My first practise webiste for Abobe Flex.

http://202.71.142.164/flash/gunjan/myindia/bin/myindia.html

It is just a good example of how flex is simple and easy. In this site User can send his own message with his name. With the help of php coding it will store in the database and available on main page when page is refreshed.

Video section :-

In the mean time one can watch the streaming videos which are available.

It only a few hours of work so one can say Flex is simple and easy.

Gunjan

gunjankumar@greymatterindia.com