
</mx:columns>
</mx:DataGrid>
<mx:Form width="260">
<mx:FormItem label="User">
<mx:TextInput id="txtUser" text="Jack" />
</mx:FormItem>
<mx:FormItem label="Message">
<mx:TextInput id="txtMessage" text=""
keyUp="messageKeyUp(event);" />
</mx:FormItem>
</mx:Form>
</mx:Application>
This looks like a complicated application, but it really isn’t. On
the bottom of the file is the user interface, which starts with
the data grid that shows the messages and then finishes with a
form that has text fields for the username and the message to
send.
The methods for the chat system start at the top of the file. The
sendMessage method creates a request to run the add.php script
on the server with the current contents of the User and Message
fields. This sendMessage script is run when the user presses the
Enter key after entering text in the text field. The message
KeyUp method looks for the user pressing Enter.
The requestMessages and onMessageFetchResult methods deal
with getting data from the server. The requestMessages method
starts the request. The onMessageFetchResult message parses
the response and starts a timer that will initiate another request
when the timer goes off.
When I start the chat widget in my browser I see something
similar to Figure 8-5.
I then type a message into the Message field and press Enter.
That starts the request to add.php. After the timer goes off, the
chat widget requests the current messages from the server and
puts the current list in the grid.
As with the other widgets, you can put this control onto any
page if you've properly installed the crossdomain.xml file in the
target PHP server.
116 | Chapter 8: Flex for Widgets
Komentáře k této Příručce