B.4. Chapter 9 Exercise
The exercise in Chapter 9 asked you to create an application that spawns two windows. The windows need to communicate with each other. This will be demonstrated by having a TextInput component in Window 1 and a Label component in Window 2, which will show the text as it is keyed into Window 1. The solution is demonstrated in Listings B-4, B-5, and Listing B-6.
If we examine Listing B-4, you will notice that there are two variables at the top of the Script block, which define the two Windows components that will be used in this application. They are defined as class variables, so that we will have a reference to them that will be used to set the text in the LabelWindow. Next, there is a function named createWindows(), which creates and opens the two windows. Now, looking at Listing B-5, you will see there is a myParent variable that was set to be a reference of the main application file within the createWindows() function within Listing B-4. You will also notice that when the TextInput contents change, there is a call to myParent.setLabelText() where the text property of the TextInput component is passed along. This setLabelText() function, which is on the main application file, then sets the text property of the Label component within the LabelWindow. The results can be seen in Figure B-5.
Example B-4. The main solution file for the Chapter 9 Exercise
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access