3.5 Building Forms in Flash MX
HTML forms are structured elements, consisting of a
<FORM>
tag
myService.myMethod(somefield_txt.text);
When you do that, you are
For that reason, building forms in Flash is somewhat of a misnomer. You are not actually building a web form, per se; you are simply creating interface elements that act as collectors of
When working with the
LoadVars
class, your server-side page has to parse the incoming form data and determine what to do with it. Working with Flash Remoting is almost like working in one environment: you simply pass arguments to remote methods and process the return value. The fact that the methods can be halfway around the world makes Flash Remoting powerful. Flash 2004 handles forms the same way as Flash MX. Flash Pro introduces an alternative to the timeline metaphor ”variously called
slides
,
screens
, or
forms
”which should not be
The UI components and other ActionScript objects each have their own properties, and some of them have methods to address these properties. Table 3-4 shows several objects that might be used in a Flash Remoting application and how their values can be grabbed through dot notation by accessing a method of the object (or accessing the text property directly in the case of a text field). Table 3-4. Accessing properties of various ActionScript objects
The AdvancedMessageBox and MessageBox components have a roundabout way of retrieving the user input. You must retrieve the index number of the button that was clicked and use it to read the label of the button from the Buttons array. To do so, define a close callback handler, using setCloseHandler( ) , that accepts two arguments: the component instance and the index of the clicked button. A typical callback function for a MessageBox or AdvancedMessageBox is shown in Example 3-2. Example 3-2. Message Box demo
// Set up the MessageBox component named
delete_mb
delete_mb.setButtons(["OK","Cancel"]);
delete_mb.setMessage("Are you sure?");
delete_mb.setTitle("Delete Record");
delete_mb.setCloseHandler("myCloseHandler");
myCloseHandler = function (myMessageBox_mb, buttonIndex) {
// Get the label of the button that was pressed
var buttonLabel = myMessageBox_mb.getButtons( )[buttonIndex];
// Do something based on which button was pressed
switch (buttonLabel.toLowerCase( )) {
case "cancel":
trace("cancel");
// In practice, do nothing when cancelled
return;
case "ok":
trace("ok");
// In practice, call the remote service when user clicks OK, such as:
//
myRemoteService.deleteRecord(myRecordNumber)
;
return;
}
};
|