Working with XML in Flash
To integrate an XML document with Flash, we need an XML document that works with Flash, one that can set up the visual movements of the action movie and define the script that will be used for the code of the action movie.
How do We Integrate XML and Macromedia Flash?
IMEX stands for Imaginary Macromedia Exchange, and IMEX is also a client server application. There has to be a protocol to interact between the client and the server. The protocol must also be designed in such a way that it fulfills all the requirements of the system.
However, for information to be traded in IMEX, there are some prior requirements which have to be fulfilled like the information that is being transmitted must be secure, and all user accounts that will be used must be protected by a password, and users need to have access to their portfolio and all the information provided must be current. In addition to this, users should be able to carry out commercial transactions using the IMEX securities.
Flash supports XML data transfers, but IMEX cannot support real time trading so for this purpose the HTTP based XML support for data is used.
How is Data Transmitted Safely?
Based on the very first requirement of the IMEX server, the data must be transmitted in hypertext transfer protocol safely and securely. Usually URL’s or Universal Resource Identifiers while playing a Flash movie will have HTTPs instead of HTTP because it means the data is secure. The IMEX servers should be capable of handling HTTPs requests for the data to be transferred through these servers.
Coming to the second condition, which is the password protection clause, every user needs to have a user name and password. The server will also have a database of passwords and usernames which will be authenticated as and when needed, for which the Flash movie will ask before it plays the movie. Once the user enters the login information, then the movie transmits that information to the XML server.
The login element however is not a predetermined value, and the XML document lets it create XML elements which are specific to the application. The protocol that will be used to carry out all these transactions is called the IMEX XML, and is an application based on XML which has specific XML elements. and they are designed especially for IMEX. Only when the password is accepted can the server respond, otherwise it returns a null value.
If the password is rejected then the server returns a login failed message. Every login session creates a session ID which will be used between the client server through out the session, and as long as the session lasts.
Coming to the third requirement, the IMEX server of users must be allowed to access current information about their portfolio, since this information is stored on the server and the Flash movie has to download this information. Once the user requests the Flash movie to be downloaded, or the portfolio information, the Flash movie transfers this request to XML. After this process the server comes back with a response with an XML element which contains portfolio information and more elements which are holding.
The fourth requirement is to trade securities. The user will enter one or more transactions of buy or sell into the Flash movie, and the movie forwards it to XML as a transaction. This transaction may contain one or more buy and sell activities. Each transaction element can have more than one trade element. To confirm the transaction, the server returns the value as a transaction reply element.
How are Visual Elements Handled?
Flash is probably one of the easiest software programs to handle. To create a flash movie all you have to do is open and click on "create movie" and provide everything required. For visual elements we need dynamic text fields.
Everything else depends on the action script, which is the key element for bringing in the XML into a flash movie. The first thing we would do is to tell Flash that XML will be used in the movie. What is done here is that a variable is created inside the flash movie which is of XML to understand the XML which will be integrated with the movie. The variable headline will have properties which can identify a XML document.
The next step is to load the XML document. A variable called the variable headline is used to associate the script, and the program which will be used to run the script. The correct path to the XML file is written in the headline. If flash is not able to find this path then the movie will not play.
So it is very important that flash find this path to play the movie. Finally, to check if everything is correct in the program, the only way to validate is if the flash movie is playing. If the movie plays then the visual elements have been handled well and also correctly. It also means that the published variable can be executed.
What is the Publish Variable?
The main function of the published variable is to parse the content from the XML document. The flash software examines the relationship to see where the content appears within a specified tag. XML data is usually grouped with other data, having a sort of parent child relationship.
Elaborately one field will be the main tag for the entire documents which will be dependant on the main tag, and the main tag which is the Broadcast tag is the parent here.
How do we load XML into Flash?
While loading a XML document into Flash, the important thing to figure out is how we load the document, and what commands need to be given so that the document gets loaded successfully. There are two main functions which can be spoken of while loading a XML document into Flash. One would be a function which will already be present, and which will probably need to be called on its own.
The other is the callback function. The call back function has to be defined by you, and should be able to respond when called by Flash and when such circumstances arise that require this function to be called.
In XML the Event is Called the Onload Event
All these functions are used in XML. The XML instances are created by using the class and object, and a construct element in flash that helps you manage XML. If XML has to work in Flash then the XML instances have to be used. So first of all before loading an XML into flash, an XML instance has to be created in Flash. While creating an XML instance there is an option where you can pass the XML string to the XML constructor. This string will have an XML which will be defined with the XML instance that has been created.
Once you have successfully defined the instance, then you can define the onload and callback functions. The callback function always has to be made onload. Using this decides when to call for a callback function, and that is after the XML content is loaded and parsed. In addition to this, a success element is also passed into the document which will pass if the loading has been successful. This will let you know if XML has been loaded or not.
XML has to load in flash and this process cannot be immediate, and it also takes time. Sometimes several seconds translate to Flash frames before XML is accessible to the XML instance. This also means that an attempt to access information within the same script while loading will be a failure.
That is if this whole process occurs in a single onload function. An onload function is usually defined in the same script like everything else, and also this onload function is not called upon unless XML is fully loaded and parsed. The onload function does everything you need to do with your XML document to be loaded.
Even if you want to populate the menu, you can do it on the onload. You can also display a family tree on the onload. The onload plays a key role in handling XML documents since it is then you have actual access to the XML document.
Preloaders can also be created for XML. Though they are not needed, it is good to know this information because there are some really huge files which you may have to load, and in those circumstances preloaders do come in handy. Making a preloader for XML is very similar to making a preloader for JPEG.
The only difference here is that instead of calling the getbytes from getbytes movie clip, you will be calling for this information from a XML instance. So preloaders for a movie can be created using a XML reference to the XML object. Whether it is a movie clip which is being played, or an XML instance, if the get bytes total and the get bytes loaded functions work, then it is sufficient.