| <?xml version="1.0" encoding="UTF-8"?> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <!DOCTYPE html |
| PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html lang="en-us" xml:lang="en-us"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| <meta name="DC.Type" content="topic"/> |
| <meta name="DC.Title" content="Storing data"/> |
| <meta name="DC.Format" content="XHTML"/> |
| <meta name="DC.Identifier" content="WS2db454920e96a9e51e63e3d11c0bf69084-7ff3_verapache"/> |
| <link rel="stylesheet" type="text/css" href="commonltr.css"/> |
| <title>Storing data</title> |
| </head> |
| <body id="WS2db454920e96a9e51e63e3d11c0bf69084-7ff3_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf69084-7ff3_verapache"><!-- --></a> |
| |
| |
| <h1 class="topictitle1">Storing data</h1> |
| |
| |
| <div> |
| <p>You use the data model feature to store data in an application |
| before it is sent to the server, or to store data sent from the |
| server before using it in the application.</p> |
| |
| </div> |
| |
| <div class="nested1" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ffe_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ffe_verapache"><!-- --></a> |
| <h2 class="topictitle2">About data models</h2> |
| |
| |
| <div> |
| <p>A <em>data model</em> is an ActionScript object that contains |
| properties that you use to store application-specific data. Communication |
| between a Flex application and the server |
| is required only to retrieve data not yet available to the Flex |
| application and to update a server-side data source with new data |
| from the Flex application. </p> |
| |
| <p> |
| You can use a data |
| model for data validation, and it can contain client-side business |
| logic. You can define a data model in MXML or ActionScript. In the model-view-controller |
| (MVC) design pattern, the data model represents the model tier.</p> |
| |
| <p>When you plan an application, you determine the kinds of data |
| that the application must store and how that data must be manipulated. |
| This helps you decide what types of data models you need. For example, |
| suppose you decide that your application must store data about employees. |
| A simple employee model might contain name, department, and e-mail |
| address properties. </p> |
| |
| </div> |
| |
| </div> |
| |
| <div class="nested1" id="WS2db454920e96a9e51e63e3d11c0bf69084-7b51_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf69084-7b51_verapache"><!-- --></a> |
| <h2 class="topictitle2">Defining a data model</h2> |
| |
| |
| <div> |
| <p>You can define a data model in an MXML tag, an ActionScript |
| function, or an ActionScript class. In general, you should use MXML-based |
| models for simple data structures, and use ActionScript for more |
| complex structures and client-side business logic. </p> |
| |
| <div class="note"><span class="notetitle">Note:</span> The <samp class="codeph"><fx:Model> </samp>and <samp class="codeph"><fx:XML></samp> tags |
| are Flex compiler tags and do not correspond directly to ActionScript |
| classes. The <em> |
| <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/" target="_blank">ActionScript 3.0 Reference for the Adobe<sup>®</sup> |
| Flash<sup>®</sup> Platform</a> |
| </em> contains information about these tags |
| and other compiler tags. </div> |
| |
| <p>You can place an <samp class="codeph"><fx:Model></samp> tag or an <samp class="codeph"><fx:XML></samp> tag |
| in a Flex application file or in an MXML component file. The tag |
| should have an <samp class="codeph">id</samp> value, and it cannot be the root |
| tag of an MXML component.</p> |
| |
| <p>Declare an <samp class="codeph"><fx:Model></samp> tag or an <samp class="codeph"><fx:XML></samp> tag |
| in an <samp class="codeph"><fx:Declarations></samp> tag. You define these |
| tags in an <samp class="codeph"><fx:Declarations></samp> tag because |
| they are not visual components.</p> |
| |
| </div> |
| |
| <div class="nested2" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ffc_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ffc_verapache"><!-- --></a> |
| <h3 class="topictitle3">The <fx:Model> tag</h3> |
| |
| |
| <div> |
| <p>The most common type of MXML-based model is the <a href="mxml/model.html" target="_blank"><fx:Model></a> tag, |
| which is compiled into an ActionScript object of type mx.utils.ObjectProxy, |
| which contains a tree of objects when your data is in a hierarchy, |
| with no type information. The leaves of the Object tree are scalar |
| values. Because models that are defined in <samp class="codeph"><fx:Model></samp> tags |
| contain no type information or business logic, you should use them |
| only for the simplest cases. Define models in ActionScript classes |
| when you need the typed properties or you want to add business logic. </p> |
| |
| <p>The following example shows an employee model declared in an <samp class="codeph"><fx:Model></samp> tag:</p> |
| |
| <pre class="noswf"><?xml version="1.0"?> |
| <!-- Models\ModelsModelTag.mxml --> |
| <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" |
| xmlns:mx="library://ns.adobe.com/flex/mx" |
| xmlns:s="library://ns.adobe.com/flex/spark"> |
| |
| <fx:Declarations> |
| <fx:Model id="employeemodel"> |
| <employee> |
| <name> |
| <first/> |
| <last/> |
| </name> |
| <department/> |
| <email/> |
| </employee> |
| </fx:Model> |
| </fx:Declarations> |
| </s:Application></pre> |
| |
| <p>An <samp class="codeph"><fx:Model></samp> child tag with no value |
| is considered null. If you want an empty string instead, you can |
| use a binding expression as the value of the tag, as the following |
| example shows:</p> |
| |
| <pre class="noswf"><?xml version="1.0"?> |
| <!-- Models\ModelTagEmptyString.mxml --> |
| <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" |
| xmlns:mx="library://ns.adobe.com/flex/mx" |
| xmlns:s="library://ns.adobe.com/flex/spark"> |
| |
| <fx:Declarations> |
| <fx:Model id="employeemodel"> |
| <employee> |
| <name> |
| <!--Fill the first property with empty string.--> |
| <first>{""}</first> |
| <!--Fill the last property with empty string.--> |
| <last>{""}</last> |
| </name> |
| <!--department is null--> |
| <department/> |
| <!--email is null--> |
| <email/> |
| </employee> |
| </fx:Model> |
| </fx:Declarations> |
| </s:Application></pre> |
| |
| </div> |
| |
| </div> |
| |
| <div class="nested2" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ffb_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ffb_verapache"><!-- --></a> |
| <h3 class="topictitle3">The <fx:XML> tag</h3> |
| |
| |
| <div> |
| <p>An <a href="mxml/xml.html" target="_blank"><fx:XML></a> tag |
| represents literal XML data. Setting the <samp class="codeph">format</samp> property |
| to <samp class="codeph">e4x</samp> creates an XML object, which implements |
| the powerful XML-handling standards defined in the ECMAScript for |
| XML specification (ECMA-357 edition 2) (known as E4X). For backward |
| compatibility, when the <samp class="codeph">format</samp> property is not explicitly |
| set to <samp class="codeph">e4x</samp>, the type of the object created is flash.xml.XMLNode.</p> |
| |
| <div class="note"><span class="notetitle">Note:</span> You currently cannot use a node within an <samp class="codeph"><fx:XML></samp> data |
| model as a binding source. </div> |
| |
| </div> |
| |
| </div> |
| |
| <div class="nested2" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ffa_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ffa_verapache"><!-- --></a> |
| <h3 class="topictitle3">Script-based models</h3> |
| |
| |
| <div> |
| <p>As an alternative to using an MXML-based model, you can |
| define a model as a variable in an <a href="mxml/script.html" target="_blank"><fx:Script></a> tag. |
| The following example shows a very simple model defined in an ActionScript |
| script block. It would be easier to declare this model in an <samp class="codeph"><fx:Model></samp> tag.</p> |
| |
| <pre class="noswf"><?xml version="1.0"?> |
| <!-- Models\ScriptModel.mxml --> |
| <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" |
| xmlns:mx="library://ns.adobe.com/flex/mx" |
| xmlns:s="library://ns.adobe.com/flex/spark"> |
| |
| <fx:Script> |
| <![CDATA[ |
| [Bindable] |
| public var myEmployee:Object={ |
| name:{ |
| first:null, |
| last:null |
| }, |
| department:null, |
| email:null |
| }; |
| ]]> |
| </fx:Script> |
| </s:Application></pre> |
| |
| <p>There is no advantage to using a script-based model instead of |
| an MXML-based model. As with MXML-based models, you cannot type |
| the properties of a script-based model. To type properties, you |
| must use a class-based model.</p> |
| |
| </div> |
| |
| </div> |
| |
| <div class="nested2" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ff9_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ff9_verapache"><!-- --></a> |
| <h3 class="topictitle3">Class-based models</h3> |
| |
| |
| <div> |
| <p>Using an ActionScript class as a model is a good option |
| when you want to store complex data structures with typed properties, |
| or when you want to execute client-side business logic by using |
| application data. Also, the type information in a class-based model |
| is retained on the server when the model is passed to a server-side |
| data service. </p> |
| |
| <p>The following example shows a model defined in an ActionScript |
| class. This model is used to store shopping cart items in an e-commerce |
| application. It also provides business logic in the form of methods |
| for adding and removing items, getting an item count, and getting |
| the total price. </p> |
| |
| <pre class="codeblock"> package |
| { |
| |
| [Bindable] |
| public class ShoppingCart { |
| public var items:Array = []; |
| |
| public var total:Number = 0; |
| |
| public var shippingCost:Number = 0; |
| |
| public function ShoppingCart() { |
| } |
| |
| public function addItem(item:Object, qty:int = 1, |
| index:int = 0):void { |
| items.splice(index, 0, { id: item.id, |
| name: item.name, |
| description: item.description, |
| image: item.image, |
| price: item.price, |
| qty: qty }); |
| total += parseFloat(item.price) * qty; |
| } |
| |
| public function removeItemAt(index:Number):void { |
| total -= parseFloat(items[index].price) * items[index].qty; |
| items.splice(index, 1); |
| if (getItemCount() == 0) |
| shippingCost = 0; |
| } |
| |
| public function getItemCount():int { |
| return items.length; |
| } |
| |
| public function getTotal():Number { |
| return total; |
| } |
| } |
| }</pre> |
| |
| <div class="note"><span class="notetitle">Note:</span> You can use properties of any recognized type |
| in a class-based model. For example, you could create an Employee |
| class, and then define properties of type Employee in another class |
| that imports Employee.</div> |
| |
| <p>You declare a class-based model as an ActionScript component |
| tag in an MXML file, as the following example shows:</p> |
| |
| <pre class="codeblock"> <local:ShoppingCart id="cart" xmlns:local="*"/></pre> |
| |
| <p>This component is in the same directory as the MXML file, as |
| indicated by the XML namespace value <samp class="codeph">*</samp>. For more |
| information about specifying the location of components, see <a href="flx_mxml_mx.html#WS2db454920e96a9e51e63e3d11c0bf5f39f-7ff3_verapache">Using |
| XML namespaces</a>.</p> |
| |
| </div> |
| |
| </div> |
| |
| </div> |
| |
| <div class="nested1" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7fff_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7fff_verapache"><!-- --></a> |
| <h2 class="topictitle2">Specifying an external source for |
| an <fx:Model> tag or <fx:XML> tag</h2> |
| |
| |
| <div> |
| <p>You can specify an external source for an <a href="mxml/model.html" target="_blank"><fx:Model></a> or <a href="mxml/xml.html" target="_blank"><fx:XML> </a>tag |
| in a <samp class="codeph">source</samp> property. Separating the content of |
| a model from the MXML that defines the user interface improves the |
| maintainability and reusability of an application.</p> |
| |
| <p>The external source file can contain static data and data binding |
| expressions, just like a model defined in the body of the <samp class="codeph"><fx:Model></samp> or <samp class="codeph"><fx:XML></samp> tag. |
| The file referenced in a <samp class="codeph">source</samp> property resides |
| on the server and not on the client machine. The compiler reads |
| the <samp class="codeph">source</samp> value and compiles the source into the application; |
| the <samp class="codeph">source</samp> value is not read at run time. To retrieve |
| XML data at run time, you can use the <samp class="codeph"><mx:HTTPService></samp> tag.</p> |
| |
| <p>Using <samp class="codeph"><fx:Model></samp> and <samp class="codeph"><fx:XML></samp> tags |
| with external sources is an easy way to reuse data model structures |
| and data binding expressions. You can also use them to prepopulate |
| user interface controls with static data by binding data from the model |
| elements into the user interface controls. </p> |
| |
| <p>The <samp class="codeph">source</samp> property accepts the names of files |
| relative to the current web application directory, as well as URLs |
| with HTTP:// prefixes. In the following example, the content of |
| the myEmployee1 data model is an XML file named content.xml in the |
| local web application directory. The content of the myEmployee2 |
| data model is a fictional HTTP URL that returns XML.</p> |
| |
| <pre class="codeblock"> <fx:Model source="employees.xml" id="employee1"/> |
| |
| <fx:Model source="http://www.somesitel.com/employees.xml" id="employee2"/></pre> |
| |
| <p>The source file must be a valid XML document with a single root |
| node. The following example shows an XML file that could be used |
| as the source of the <samp class="codeph"><fx:Model source="employees.xml" id="Model1"/></samp> tag. </p> |
| |
| <pre class="codeblock"> <?xml version="1.0"?> |
| <employees> |
| <employee> |
| <name>John Doe</name> |
| <phone>555-777-66555</phone> |
| <email>jdoe@fictitious.com</email> |
| <active>true</active> |
| </employee> |
| <employee> |
| <name>Jane Doe</name> |
| <phone>555-777-66555</phone> |
| <email>jndoe@fictitious.com</email> |
| <active>true</active> |
| </employee> |
| </employees></pre> |
| |
| </div> |
| |
| </div> |
| |
| <div class="nested1" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ff8_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ff8_verapache"><!-- --></a> |
| <h2 class="topictitle2">Using validators with a data model</h2> |
| |
| |
| <div> |
| <p>To validate the data stored in a data model, you use validators. |
| In the following example, the <samp class="codeph"><mx:EmailValidator></samp>, <samp class="codeph"><mx:PhoneNumberValidator></samp>, <samp class="codeph"><mx:ZipCodeValidator></samp>, |
| and <samp class="codeph"><mx:SocialSecurityValidator></samp> tags declare |
| validators that validate the e-mail, phone, zip, and ssn fields |
| of the registration data model. The validators generate error messages |
| when a user enters incorrect data in TextInput controls that are |
| bound to the data model fields. </p> |
| |
| <pre class="codeblock"><?xml version="1.0"?> |
| <!-- Models\ModelWithValidator.mxml --> |
| <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" |
| xmlns:mx="library://ns.adobe.com/flex/mx" |
| xmlns:s="library://ns.adobe.com/flex/spark"> |
| |
| <fx:Declarations> |
| <fx:Model id="reg"> |
| <registration> |
| <name>{username.text}</name> |
| <email>{email.text}</email> |
| <phone>{phone.text}</phone> |
| <zip>{zip.text}</zip> |
| <ssn>{ssn.text}</ssn> |
| </registration> |
| </fx:Model> |
| |
| <mx:Validator required="true" |
| source="{reg}" property="name" |
| trigger="{submit}" |
| triggerEvent="click" |
| listener="{username}"/> |
| <mx:EmailValidator source="{reg}" property="email" |
| trigger="{submit}" |
| triggerEvent="click" |
| listener="{email}"/> |
| <mx:PhoneNumberValidator source="{reg}" property="phone" |
| trigger="{submit}" |
| triggerEvent="click" |
| listener="{phone}"/> |
| <mx:ZipCodeValidator source="{reg}" property="zip" |
| trigger="{submit}" |
| triggerEvent="click" |
| listener="{zip}"/> |
| <mx:SocialSecurityValidator source="{reg}" property="ssn" |
| trigger="{submit}" |
| triggerEvent="click" |
| listener="{ssn}"/> |
| </fx:Declarations> |
| |
| <!-- Form contains user input controls. --> |
| <s:Form> |
| <s:FormItem label="Name" required="true"> |
| <s:TextInput id="username" width="200"/> |
| </s:FormItem> |
| <s:FormItem label="Email" required="true"> |
| <s:TextInput id="email" width="200"/> |
| </s:FormItem> |
| <s:FormItem label="Phone" required="true"> |
| <s:TextInput id="phone" width="200"/> |
| </s:FormItem> |
| <s:FormItem label="Zip" required="true"> |
| <s:TextInput id="zip" width="60"/> |
| </s:FormItem> |
| <s:FormItem label="Social Security" required="true"> |
| <s:TextInput id="ssn" width="200"/> |
| </s:FormItem> |
| <s:FormItem> |
| <!-- User clicks Button to trigger validation. --> |
| <s:Button id="submit" label="Validate"/> |
| </s:FormItem> |
| </s:Form> |
| </s:Application></pre> |
| |
| <p>This example cleanly separates the user interface and application-specific |
| data. You could easily extend it to create a three-tier architecture |
| by binding data from the registration data model into an RPC service |
| request. You could also bind user input data directly into an RPC |
| service request, which itself is a data model.</p> |
| |
| <p> |
| |
| |
| For |
| more information about validators, see <a href="flx_validators_va.html#WS2db454920e96a9e51e63e3d11c0bf69084-7ff0_verapache">Validating |
| Data</a>.</p> |
| |
| </div> |
| |
| </div> |
| |
| <div class="nested1" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ff7_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ff7_verapache"><!-- --></a> |
| <h2 class="topictitle2">Using a data model as a value object</h2> |
| |
| |
| <div> |
| <p>You can use a data model as a value object, which acts |
| as a central repository for a set of data returned from method calls |
| on one or more objects. This makes it easier to manage and work |
| with data in an application. </p> |
| |
| <p> |
| In |
| the following example, the tentModel data model stores the results |
| of a web service operation. The TentDetail component is a custom |
| MXML component that gets its data from the tentModel data model |
| and displays details for the currently selected tent. </p> |
| |
| <pre class="codeblock"> ... |
| <!-- Data model stores data from selected tent. --> |
| <strong><fx:Model id="tentModel"></strong> |
| <tent> |
| <strong><name>{selectedTent.name}</name></strong> |
| <strong><sku>{selectedTent.sku}</sku></strong> |
| <strong><capacity>{selectedTent.capacity}</capacity></strong> |
| <strong><season>{selectedTent.seasonStr}</season></strong> |
| <strong><type>{selectedTent.typeStr}</type></strong> |
| <strong><floorarea>{selectedTent.floorArea}</floorarea></strong> |
| <strong><waterproof>{getWaterProof(selectedTent.waterProof)}</waterproof></strong> |
| <strong><weight>{getWeight(selectedTent)}</weight></strong> |
| <strong><price>{selectedTent.price}</price></strong> |
| </tent> |
| <strong></fx:Model></strong> |
| ... |
| <TentDetail id="detail" tent="{tentModel}"/> |
| ...</pre> |
| |
| <p>The following example shows the MXML source code for the TentDetail component. |
| References to the <samp class="codeph">tent</samp> property, which contains |
| the tentModel data model, and the corresponding <samp class="codeph">tentModel </samp>properties |
| are highlighted in boldface.</p> |
| |
| <div class="p"> |
| <pre class="noswf"><?xml version="1.0" encoding="utf-8"?> |
| <!-- Models\myComponents\TentDetail.mxml--> |
| <s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009" |
| xmlns:s="library://ns.adobe.com/flex/spark" |
| xmlns:mx="library://ns.adobe.com/flex/mx" |
| title="Tent Details"> |
| |
| <fx:Script> |
| <![CDATA[ |
| [Bindable] |
| public var tent:Object; |
| ]]> |
| </fx:Script> |
| |
| <fx:Style> |
| .title{fontFamily:Arial;fontWeight:bold;color:#3D3D3D;fontSize:16pt;} |
| .flabelColor |
| {fontFamily:Arial;fontWeight:bold;color:#3D3D3D;fontSize:11pt} |
| .productSpec{fontFamily:Arial;color:#5B5B5B;fontSize:10pt} |
| </fx:Style> |
| |
| <s:VGroup paddingLeft="10" paddingTop="10" paddingRight="10"> |
| <s:Form verticalGap="0" paddingLeft="10" paddingTop="10" |
| paddingRight="10" paddingBottom="0"> |
| |
| <s:VGroup width="209" height="213"> |
| <s:Image width="207" height="211" |
| source="./images/{tent.sku}_detail.jpg"/> |
| </s:VGroup> |
| |
| <s:FormHeading label="{tent.name}" paddingTop="1" |
| styleName="title"/> |
| |
| <mx:HRule width="209"/> |
| |
| <s:FormItem label="Capacity" styleName="flabelColor"> |
| <s:Label text="{tent.capacity} person" |
| styleName="productSpec"/> |
| </s:FormItem> |
| <s:FormItem label="Season" |
| styleName="flabelColor"> |
| <s:Label text="{tent.season}" |
| styleName="productSpec"/> |
| </s:FormItem> |
| <s:FormItem label="Type" styleName="flabelColor"> |
| <s:Label text="{tent.type}" |
| styleName="productSpec"/> |
| </s:FormItem> |
| <s:FormItem label="Floor Area" styleName="flabelColor"> |
| <s:Label text="{tent.floorarea} |
| square feet" styleName="productSpec"/> |
| </s:FormItem> |
| <s:FormItem label="Weather" styleName="flabelColor"> |
| <s:Label text="{tent.waterproof}" |
| styleName="productSpec"/> |
| </s:FormItem> |
| <s:FormItem label="Weight" styleName="flabelColor"> |
| <s:Label text="{tent.weight}" |
| styleName="productSpec"/> |
| </s:FormItem> |
| </s:Form> |
| </s:VGroup> |
| </s:Panel></pre> |
| |
| </div> |
| |
| </div> |
| |
| </div> |
| |
| <div class="nested1" id="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ff6_verapache"><a name="WS2db454920e96a9e51e63e3d11c0bf66ba1-7ff6_verapache"><!-- --></a> |
| <h2 class="topictitle2">Binding data into an XML data model</h2> |
| |
| |
| <div> |
| <p>Flex compiles the <samp class="codeph"><fx:XML></samp> tag into |
| literal XML data in an ActionScript xml.XMLNode or XML object. This |
| is different from the <samp class="codeph"><fx:Model></samp> tag, which Flex |
| compiles into an Action object that contains a tree of ActionScript |
| objects. To bind data into an <samp class="codeph"><fx:XML></samp> data |
| model, you can use the curly braces syntax the same way you do with |
| other data models. However, you cannot use a node within the data |
| model as a binding source. </p> |
| |
| <p>It’s not a best practice to use the <samp class="codeph"><mx:Binding></samp> tag |
| for this type of binding because doing so requires you to write |
| an appropriate ActionScript XML command as the <samp class="codeph">destination</samp> property |
| of the <samp class="codeph"><mx:Binding></samp> tag. For more information |
| about the <samp class="codeph"><fx:XML></samp> tag, see <a href="flx_datamodels_dm.html#WS2db454920e96a9e51e63e3d11c0bf69084-7b51_verapache">Defining |
| a data model</a>.</p> |
| |
| <p>The following example shows an <samp class="codeph"><fx:XML></samp> data |
| model with binding destinations in curly braces:</p> |
| |
| <pre class="noswf"><?xml version="1.0"?> |
| <!-- Models\XMLBinding.mxml --> |
| <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" |
| xmlns:mx="library://ns.adobe.com/flex/mx" |
| xmlns:s="library://ns.adobe.com/flex/spark"> |
| <s:layout> |
| <s:VerticalLayout/> |
| </s:layout> |
| |
| <fx:Declarations> |
| <fx:XML id="myEmployee" format="e4x"> |
| <employee> |
| <name> |
| <first>{firstName.text}</first> |
| <last>{lastName.text}</last> |
| </name> |
| <department>{department.text}</department> |
| <email>{email.text}</email> |
| </employee> |
| </fx:XML> |
| </fx:Declarations> |
| |
| <s:TextInput id="firstName"/> |
| <s:TextInput id="lastName"/> |
| <s:TextInput id="department"/> |
| <s:TextInput id="email"/> |
| </s:Application></pre> |
| |
| <p/> |
| |
| </div> |
| |
| <p>Adobe and Adobe Flash Platform are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries and are used by permission from Adobe. No other license to the Adobe trademarks are granted.</p> |
| </div> |
| |
| |
| </body> |
| </html> |