Hear you can find latest action script code and all related solution using flash actionscript or call free anil nain 9416077273
Saturday, May 30, 2009
Thursday, December 18, 2008
अनिल नैन अबाउट इवेंट handler
Application programmers (the folks who make the everyday programs you use for Windows or Macintosh)
have long known that the key to graphical user interface (GUI) programming is events. So, what is an event,
and why are events so important? To answer that question, take a closer look at GUIs.
A GUI is, at its most base form, a large menu that lets the user choose what he wants to do. The problem is that
how the user does this choosing is based on a lot of complex interactions: keys being pressed, keys being
released, the mouse moving, a mouse button being pressed—you get the idea. Each one of these interactions is
an event. It occurs at a specific time and may have information associated with it. (The key that was pressed,
for example.) Now, events aren't limited to forms of user input. Things such as timers, network connections,
and file I/O also can create events. Basically, anytime you are working with something external to your code,
whether that is the hard disk, the user, or even time, you will be working with events.
Methods of Event Handling
There are two main methods to work with events in Flash MX: callbacks and listeners. Both have their
strengths and weaknesses as well as situations for which they are best suited. The most important thing to
remember about both methods is that organization and documentation are key to writing maintainable code.
Callbacks
The first method of working with events is known as a callback. Callbacks take advantage of the fact that
ActionScript is a highly forgiving language. In particular, callbacks execute a function that doesn't exist, and
Flash won't generate an error or even complain. Some forms of callbacks also utilize the fact that you can
overwrite any variable in Flash at any time, which includes functions.
मिग्रेशन अच्शन्स्क्रिप्त
The first thing to understand about updating existing (Flash MX) ActionScript to ActionScript 2.0 is that, in many cases, it's not necessary. ActionScript you wrote in earlier versions of Flash continues to work in Flash MX 2004 and Flash Player 7.
Migrating your code from ActionScript 1.0 to ActionScript 2.0 is beneficial mainly in the following circumstances:
For a large-scale Flash application or presentation that contains a lot of code, using ActionScript 2.0 simplifies the development process and provides more debugging information than ActionScript 1.0.
To upgrade OOP programs that you created originally in Flash MX or Flash 5, using ActionScript 2.0 makes maintaining and modifying the code much easier.
You're curious about OOP and want to learn about it in a familiar authoring environment.
अनिल नैन अबाउट एक्शन सकत
ActionScript 2.0 introduces several new programming keywords and concepts, including classes, inheritance, and interfaces. These concepts comprise what is commonly known as object-oriented programming.
Classes you create in ActionScript must be stored in separate ActionScript (AS) files; you can't create classes in a Flash (FLA) frame or button script. Some important points about class files:
Only one class can be defined per AS class file.
The name of the file that contains the class must match the class name.
ActionScript class files must be located in a folder where the Flash compiler looks for classes.
You can combine several classes in a folder to create a package.
Read Full Tutorial
अनिल नैन अबाउट Differences Between ActionScript 1.0 and 2.0
If you're familiar with ActionScript 1.0, you'll find that ActionScript 2.0 is similar, yet it has several subtle but important differences. In this section, we examine some of them so that you can take your hard-earned knowledge of ActionScript 1 and put it to use with ActionScript 2.0.
Before we look at these differences, let us first tell you up front that if you want to stick with what you know (programming in ActionScript 1.0), then by all means, do so. ActionScript 1.0 syntax still works in Flash MX 2004. But while this may be the case, and you do have a choice, we recommend you take the time to learn ActionScript 2.0, for a number of reasons.
First, there may come a time when a version of Flash is released that no longer supports ActionScript 1.0. Time spent learning version 2.0 now will be time you might have to spend down the road anyway. And while we can't guarantee it, don't expect ActionScript to jump to version 3.0 any time soon (if ever), because version 2.0 is now built around professional programming language concepts that have stood the test of time. As a matter of fact, outside of a few syntactical differences, writing ActionScript 2.0 code is not much different from writing Java code.
That's right; if you take the time to learn ActionScript 2.0, you'll be able to quickly transition your knowledge to the Java universe, where industrial-strength, cross-platform applications are standard. Consider learning ActionScript: it's a two-for-one deal!
Second, by its very nature and requirements, ActionScript 2.0 will force you to become a more efficient, organized, and better coder. As you will soon see, ActionScript 2.0 has some very strict requirements about how things are done. It's a lot less forgiving than ActionScript 1.0. This may seem like a bad thing, but it actually prevents you from being too sloppy with your scripts, which can make finding bugs a pain, and which can make updating a project months later an arduous task.
Finally, if speed is important to you, you'll be happy to know that ActionScript 2.0 has been shown to be three to seven times faster than ActionScript 1.0. This speed increase will promote the development of even more robust Flash applications.
Let's next look at some of the main differences you'll find between ActionScript 1.0 and ActionScript 2.0.
Case Sensitivity
In ActionScript 1.0, these variable names referenced the same variable:
myVariable MyVariable
In ActionScript 2.0, however, they would be considered two separate variables due to the case difference in their spelling; the first variable begins with a lowercase character, while the second an uppercase character. In fact, all of the following are considered different elements in ActionScript 2.0:
myName MyName MYNAME myname myNAME
This case sensitivity rule applies to all elements in ActionScript 2.0, including instance names, keywords, method names, and so on. Thus, while this syntax will stop all sounds from playing:
stopAllSounds();
this will cause an error:
stopallsounds();
Tip: One easy way of testing for case errors is to press the Check Syntax button on the Actions panel. Errors resulting from case mismatches will appear in the output window.
Strict Data Typing
Variables are used to contain data. This data comes in many forms, including strings of text, numbers, true/false values, references to objects such as movie clip instances, and so on. In ActionScript 1.0, when creating a variable, Flash would automatically assign a data type to it. In this example, Flash understood that the value on the right was of the Number data type:
myVariable = 36;
While Flash will still automatically recognize this variable as holding a Number data type, ActionScript 2.0 introduces what is known as strict data typing, which gives you more control over setting a variable's data type. Here's how it works.
When creating a variable with ActionScript 2.0, you use this syntax not only to create the variable, but also to assign its data type at the same time:
var myVariable:Number = 36;
As you can see, this syntax is not that different from what you're used to using in ActionScript 1.0. The difference is the addition of the var keyword, and the explicit declaration that this variable will hold a number, as indicated by the :Number syntax.
A variable that will hold a string looks like this:
var myOtherVariable:String = "Hello";
In addition to assigning data types to regular variables, strict data typing is used in the creation of object instances:
var myArray:Array = new Array();
and function definitions:
function myFunction (name:String, age:Number)
Note: Both of these types of strict data typing will be explained in greater depth later in the book.
How can all those extra keystrokes be an enhancement? Well, there are several ways.
If you're familiar with the Actions panel's ability to provide code hints (which we will discuss shortly), you'll be happy to know that strict data typing activates code hinting for named elements. For example, if you create an Array object using the syntax:
var myArray:Array = new Array();
the Actions panel will recognize from that point forward that any reference to myArray is a reference to an Array object, and it will automatically provide Array object code hints whenever you script that object. In some cases, this new ability eliminates the need for a suffix (_array, _xml, and _color, for example), which was one of the ways that Flash MX enabled code hinting for an object. While the new syntax requires a few more keystrokes, you'll save a few because you no longer have to add suffixes to elements' names, so consider it a decent trade-off.
Note: You'll notice we said that in some cases the new ability eliminates the need for suffixes. Visual elements (movie clip instances, buttons, text fields, and components, for example) are not created and named in the same manner as data elements. For this reason, suffixes for these elements' names (such as _mc, _btn, and _txt) are still useful. For this book, we will generally use suffixes only for visual elements.
Code hinting isn't the only benefit to strict data typing. By indicating the type of data a variable will hold, you save the Flash player a whole lot of time trying to figure it out on its own. When the Flash player is running your application, Flash needs to keep track of the type of data each variable contains. If you use strict data typing, you make this process a lot easier and less processor-intensive for the Flash player. As a result, your scripts will execute much faster. If you want to increase the speed of your applications, use strict data typing.
Finally, strict data typing can be a very simple way of helping you uncover bugs in your code. Here's an example:
var favoriteBand:String;
This line of script creates a variable named favoriteBand, which has been strictly typed to hold a String.
Later in your script you assign this variable a value or give it a new one using the syntax:
favoriteBand = "The Beatles";
However, if somewhere in your script you use something like this syntax:
favoriteBand = 46;
the Output panel will open and display a "Type mismatch" error when you attempt to export (compile) your movie. This is an error indicating that you've attempted to assign an incorrect value type to a variable. In our example, we've attempted to assign a numeric value (Number data type) to a variable that has been set up to hold a string value.
This functionality can help prevent a number of bugs that can result from simple mistakes you might make when assigning values to variables.
Class Structure
Perhaps the biggest change in ActionScript 2.0 is the way that object-oriented programming is implemented. For example, with ActionScript 1.0, a custom class of objects was defined this way:
_global.Person = function (name, age){ this.name = name; this.age = age; }
In ActionScript 2.0, the same class is created using this syntax:
class Person { var name:String; var age:Number; function Person (name:String, age:Number){ this.name = name; this.age = age; } }
Notice the use of the new class keyword. This syntax is very similar to the syntax for creating classes of objects in Java. As you learn more about this syntax (which we won't discuss in detail at this point), you'll quickly see its benefits over ActionScript 1.0.
Another subtle difference in creating custom classes of objects between ActionScript 1.0 and 2.0 is that the script that contains the class definition must exist in its own external .as file. This means that the script for defining the Person class would need to be saved as an external .as file (which is nothing more than a text file with a .as file extension) named Person.as. This is different from ActionScript 1.0, which allows you to place the code for a class definition on Frame 1 of a movie clip's timeline. This is no longer possible when creating content for the Flash 7 player. Class definitions must exist in an external .as file. We'll discuss this functionality in Lesson 7, "Creating Custom Classes." For now, be aware of the difference.
Note: You can still place scripts on frames, buttons, etc., but class definitions must exist in their own .as files.
To make the creation of .as files as easy as possible, Flash MX 2004 now provides a stand-alone ActionScript editor, which is separate from the Actions panel, and which is used for nothing more than the creation and saving of .as files. Later in this lesson, we'll look at both the Actions panel and the stand-alone ActionScript editor.
There are other differences between ActionScript 1.0 and ActionScript 2.0, but this brief overview should provide you with enough insight to get started if you've worked with ActionScript 1.0.
अनिल नैन अबाउट Object-Oriented Programming
ActionScript 2.0 is fully object-oriented programming (OOP) language that provides several benefits to programmers, especially when creating large-scale Flash applications or presentations. OOP encourages reusability. You reuse a class you created in ActionScript 2.0 by inheriting the functionality of that class in other classes. The modular nature of OOP lets you replace or swap components of an application without changing the application's structure. Finally, the fundamental metaphors of OOP design closely mirror the natural world (objects that have internal states and can do certain things), which speeds and facilitates the application design process.
Like ActionScript, OOP languages are based on the concept of classes and instances. A class defines all of the properties that distinguish a series of objects—it defines a category of object. A class describes the properties (data) and methods (behaviors) for an object, much like an architectural blueprint describes the characteristics of a building. The Date class is an intrinsic ActionScript class. Using the Date class you can make many instances. Each instance, or Date object, can represent a different (or the same) date. For example, you can make a Date object to represent August 1, 2010 and another to represent August 2, 2010. Each object inherits the same functionality from the Date class. However, each instance is an independent object much as two buildings built from the same blueprint are unique instances.
Classes define data types. When an application has a new logical classification for data that doesn't fit any pre-existing data types, you can write a new class. For example, if you are building an application that showcases t-shirts then you can write a TShirt class that defines the characteristics of that data type such as color and style. To define a class, you use the class keyword in an external script file. You can create an external script file in the Flash authoring tool by selecting File > New > ActionScript File.
As always, ActionScript 2.0 provides several powerful and familiar OOP concepts and keywords (such as class, interface, and package) found in other programming languages, such as Java. The programming language lets you build program structures that are reusable, scalable, robust, and maintainable. It can also decrease development time by providing users with thorough coding assistance and debugging information. You can use ActionScript 2.0 to create objects and establish inheritance, and to create custom classes and extend the top-level and built-in classes in Flash.
Flash Basic 8 and Flash Professional 8 include approximately 65 top-level classes that provide everything from core data types (Array, Boolean, Date, and so on), to custom errors and events, as well as several ways to load external content (XML, images, variables, and more). You can also write your own custom classes and integrate them into your Flash documents, or extend the top-level classes and add your own functionality or modify existing functionality. You write a custom class in an external ActionScript (AS) file and you can import it into your application when you compile the FLA file. Classes can be very useful when you build larger Flash applications because you can organize a lot of the application's complexity in external class files. When you move a lot of the logic into a custom class, you can not only make the code easier to reuse, but you can also “hide” some of the methods and properties from other parts of the ActionScript code. This helps you prevent other developers on the team from accessing sensitive information, or changing data that shouldn't be changed.
When you use a class, you can also extend existing classes and add new functionality or modify existing functionality. For example, if you create three very similar classes, you can write a base class (abstract) and then write three classes (implementations) that extend the base class. These three subclasses can add additional methods and properties, so that you don't need to create three class files that all duplicate the same code and logic.
Another benefit of using classes is code reusability. For example, if you create a custom class that creates a custom progress bar using the Drawing API, you could save the progress bar class in your classpath and reuse the same code in all of your Flash documents by importing the custom class. For more information on setting the classpath, see About Importing Class Files and About Setting and Modifying the classpath.
Wednesday, November 12, 2008
Flash WebServiceConnector component
The WebServiceConnector component (Flash Professional)
The WebServiceConnector component enables you to access remote methods exposed by a server using the industry-standard SOAP (Simple Object Access Protocol) protocol. A web service may accept parameters and return a result. Using the Flash MX Professional 2004 authoring tool and the WebServiceConnector component, you can introspect, access, and bind data between a remote web service and your Flash application. A single instance of a WebServiceConnector component can be used to make multiple calls to the same operation. To call more than one operation, though, you need to use a different instance of a WebServiceConnector component for each operation.
A web service's methods (sometimes referred to as operations) are defined by a Web Service Description Language (WSDL) file. The WSDL file specifies a list of operations, parameters, and results (referred to as a schema) that are exposed by the web service.
WSDL files are accessible using a URL. In Flash MX Professional 2004, you can view the schema of any web service by entering the URL for its WSDL file using the Web Services panel. Once you identify a WSDL file, the web service is available to any application you create.
Note: Keep in mind that access to a web service (as with any external data) is subject to Flash Player security features. See About data connectivity and security in Flash Player (Flash Professional only).
For more information on the WebServiceConnector component, including its properties, methods, and events, see WebServiceConnector (Flash Professional only) (you may need to update your Help system to see this information).
WebServiceConnector component parameters
The following are the WebServiceConnector component parameters:
operation A string that is the name of a method of the web service. In the authoring UI, this appears as a pop-up menu, which is updated any time you change the WSDLURL.
multipleSimultaneousAllowed A Boolean value; when this parameter is set to true, it allows a trigger() operation to initiate when another trigger() operation is already in progress. Multiple simultaneous trigger() operations might not be completed in the same order they were called. Also, Flash Player may place limits on the number of simultaneous network operations. This limit varies by version and platform. When the parameter is set to false, a trigger() operation cannot initiate if another one is in progress.
suppressInvalidCalls A Boolean value; when this parameter is set to true, it suppresses the trigger() operation if the data parameters are invalid. When it is set to false, the trigger() operation executes and uses invalid data if necessary.
WSDLURL A string that is the URL of a web service WSDL file.
Common workflow for the WebServiceConnector component
The typical workflow for the WebServiceConnector component is as follows.
To use a WebServiceConnector component:
- Use the Web Services panel to enter the URL for a web service WSDL file.
- Add a call to a method of the web service by selecting the method, right-clicking (Windows) or Control-clicking (Macintosh), and selecting Add Method Call from the context menu. This creates a WebServiceConnector component instance in your application. The schema for the component can then be found on the Schema tab of the Component Inspector panel. You are free to edit this schema as needed—for example, to provide additional formatting or validation settings.
Note: The schema for the
paramsandresultscomponent properties is updated each time the author changes theWSDLURLoroperationparameter. This overwrites any settings that you have edited. - Use the Binding tab in the Component Inspector panel to bind the web service parameters and results that are now defined in your schema to components within your application.
- Add a trigger to initiate the data binding operation: use the Trigger Data Source behavior attached to a button, or add ActionScript.
Schemas for web services
The schema for a web service is defined through its WSDL file. Flash MX Professional 2004 has built-in support for introspecting a WSDL and generating the schema.
The following example demonstrates how to view the schema for a web service.
Note: This example requires an active Internet connection, because it uses a public web service. If you use a web service in your application, the web service must be located in the same domain as the SWF file for your application in order for the application to work in a web browser. See Applications and web services.
- Drag a WebServiceConnector component to the Stage.
- Select the WSDLURL parameter, and type the following URL:
http://www.xmethods.net/sd/2001/BabelFishService.wsdl
- Select Operation and select the BabelFish method.
- Click the Schema tab. You will now see the following auto-generated schema:

This is a schematic representation of the service that you are calling. The parameters as well as result structure are defined within the schema. This schema states that the BabelFish Service expects two string parameters when it is called and will return a string as the result of the call.
The items identified within the schema can now be bound to a variety of UI controls to provide values for the parameters or to display the results of the web service.
Applications and web services
Many developers are interested in using an industry standard such as SOAP web services as the data-exchange mechanism between their client and server. One reason this approach is gaining favor is the increasing number of popular servers that support exposure of logic using SOAP.
However, there may be cases where you want the client software to consume web services that are published by third parties or hosted on servers that fall outside the Flash Player sandbox. There are several ways to make this work, while still preserving the end-user security and privacy that the Flash Player sandbox provides. These approaches involve the creation of an intermediary object that resides on the server to act as a bridge between your client and the public services you want to consume. This approach offers several advantages:
- Public web services can be aggregated. With this approach you can provide fail-over safety and load balancing when a request is made for data.
- You keep control over the flow of data in your application. If the web service goes away or the URL is down, you can decide how to respond.
- Data can be optimized. Multiple requests can be cached.
- You can have custom error handling. You can determine what errors to send back to the client.
- Data can be manipulated, converted, or combined. You can pull data from several sources and return one data packet with the combined information.
Many of the SOAP-based applications that you build will consume private web services hosted on your server. Once you have determined the best way to implement and expose your own web services, it is easy to make public web services available to your client application. When you are in control of the server, you can offer a complete solution. The server is the ideal place for business logic that can determine the best way to respond to requests for data and the results that should be sent back to the client. This is also the most secure way to build an application. The server can provide additional processing to make sure that users have access only to certain services as well as protect the client from making calls to malicious services that can return bad data. See About data connectivity and security in Flash Player (Flash Professional only).
Lazy decoding
When the WebServiceConnector component receives multiple records of data from a web service, it translates them into an ActionScript array so that they are accessible within your application. Translating multiple records of data from XML/SOAP into ActionScript native data can be a very time-consuming process (large arrays can take seconds, or tens of seconds). The WebServiceConnector component supports a feature called lazy decoding, which defers this translation. Therefore, result values that are arrays are not immediately translated from XML to ActionScript. Instead, the result value passed to the user is a special object that acts similarly to an array and translates the XML data only when it is actually requested. You request the data by using the command myArray[myIndex]. The net effect of this feature is to improve the perceived performance of web services by spreading the workload over a longer period of time.
Note: The result value can be accessed only by using the myArray[myIndex] syntax. It cannot be accessed using a for..in loop such as for (var i in myArray).
To use a WebServiceConnector component: