Tài liệu Foundation Flash CS5 For Designers- P14 doc

50 302 0
Tài liệu Foundation Flash CS5 For Designers- P14 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BUILDING INTERFACES WITH THE UI COMPONENTS 629 Here’s an exercise designed to show you how the ProgressBar component works: 1. Open the ProgressBar.fla file in this chapter’s Exercise folder. Note that a ProgressBar instance exists in frame 1 with the instance name pb, as well as a text field with the instance name output. In frame 5, you’ll find a fairly heavy image of red leaves on a tree branch, snapped by one of the authors. In the scripts layer, there’s a MovieClip.stop() method in frames 1 and 5. 2. Click into frame 1 of the scripts layer. Note the existing stop() method. Type the following ActionScript after that method (new code in bold): stop(); root.loaderInfo.addEventListener(Event.COMPLETE, completeHandler); function completeHandler(evt:Event):void { play(); }; pb.source = root.loaderInfo; Here, first, the playhead stops at this frame. Next, an Event.COMPLETE handler is assigned to the LoaderInfo instance associated with the root property of the main timeline. Say again? Yeah, this one is a bit different from what you’ve seen. In the same way that the stop() method is invoked here on the main timeline—appearing, as it does, without an object reference prefix—the root property is also being invoked implicitly on the main timeline. (root is a property of the DisplayObject class, which means MovieClip and other classes have it by inheritance.) The root property refers to the topmost display object in a given display list. In this context, it essentially refers to the display list of the main timeline (everything that’s visible—or will be visible—on the main timeline, including that onion photo on frame 5). The main timeline, being a movie clip, features a loaderInfo property, which points to an instance of the LoaderInfo class that (as its name suggests) manages loading information for the object at hand. In this case, when the movie itself has completed loading, the Event.COMPLETE event is dispatched, and the completeHandler() function invokes MovieClip.play() on the main timeline, causing the playhead to resume play until it encounters the second stop() method on frame 5. It’s frame 5 that reveals the image. Notice that, so far, none of this yet touches the ProgressBar component. That happens only at this point. Immediately after the event handler, the ProgressBar.source property, by way of the pb instance, is associated with the root.loaderInfo reference. As if by magic, that’s all it takes to set the thermometer- style movement in motion. 3. Test the movie. When the SWF launches, select View ➤ Simulate Download from the SWF’s menu bar to see the ProgressBar component in action. Selecting View ➤ Download Settings lets you select the speed of the simulated Internet connection. 4. Close the SWF. www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 11 630 5. Let’s also display a text message indicating a percent loaded. In the Actions panel, add a few more lines below the existing code: pb.addEventListener(ProgressEvent.PROGRESS, progressHandler); function progressHandler (evt:ProgressEvent):void { output.text = Math.floor(pb.percentComplete).toString() + "%"; }; The ProgressBar component features a percentComplete property, which we’re using here. The addEventListener() method is invoked against the pb instance, listening for a ProgressEvent.PROGRESS event. The function it performs sets the output text field’s text property to a rounded-down string version of the progress percentage, with the percent sign tacked onto the end for good measure. RadioButton component Radio buttons are gregarious. They belong in groups and courteously defer to each other as each takes the spotlight. What are we talking about? We’re talking about a component identical in functionality to radio buttons in HTML. Groups of RadioButton components are used to let the user make a single selection from a multiple-choice set, as shown in Figure 11-22. Figure 11-22. The RadioButton component lets the user make a single selection from a multiple-choice set. This book was purchased by flashfast1@gmail.com www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. BUILDING INTERFACES WITH THE UI COMPONENTS 631 Double-clicking a RadioButton instance provides access to its skins, which you can edit as described in the “Button component” section. Styling works the same way. Using one or more instances of the RadioButton component in your movie will add 16KB to the SWF if no other components share the load. To see RadioButton components in action, open the RadioButton.fla file in this chapter’s Exercise file. Because radio buttons work in groups, the Component Parameters tab of the Properties panel has a “collective consciousness” parameter we haven’t seen with other components: groupName. Select each of the three radio buttons in turn, and verify that each belongs to the same group, syntax, even though each has its own distinct label: Method, Property, and Operator (see Figure 11-23). Note also the empty dynamic text field whose instance name is output. You’re about to wire up the radio buttons to that text field. Figure 11-23. RadioButton instances must be associated with a group name. Click into frame 1 of the scripts layer, and type the following very condensed but interesting ActionScript: rb1.group.addEventListener(Event.CHANGE, changeHandler); function changeHandler(evt:Event):void { output.text = rb1.group.selection.label; }; What makes this interesting? In most of the event-handling samples in this chapter, you’ve invoked the addEventListener() method on an object that you personally gave an instance name. Here, that might have been rb1, but that’s not the focal point in this case. You’re not adding an event listener to a particular radio button but rather to the group to which these buttons belong. The RadioButton class provides a group property, which means that each instance knows to which group it belongs. It’s the group that dispatches the Event.CHANGE event, which occurs when any one of these radio buttons is clicked. It doesn’t matter which radio button’s group property you use, because all of them point to the same RadioButtonGroup instance. The associated function updates the output text field by sending it the www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 11 632 selected button in this group—in particular, that button’s label property, which is either Method, Property, or Operator. Note that the Component Parameters area gives you the option to supply a value for each radio button. This allows you to say one thing and do another, just as in the List example. The difference is that the List choices were label and data , and here they are label and value , and the data type of value is typed as Object , not String . The text field wants a string, so you would change that line of ActionScript to output.text = rb1.group.selection.value.toString(); . For example, if you change the value of the Operator RadioButton to Correct, you turn this exercise into a quiz. ScrollPane component The ScrollPane component lets you have eyes bigger than your stomach. If you want to display a super- large image—so large that you’ll need scrollbars—ScrollPane is your component; Figure 11-24 shows it in action. Figure 11-24. ScrollPane provides optional scrollbars to accommodate oversized content. ScrollPane has nested skins because of its scrollbars, so double-clicking an instance during authoring will open its skin elements in tiers. Styling works the same as described in the “Button component” section, although with no text elements, most of your customization work will probably center around skins. www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. BUILDING INTERFACES WITH THE UI COMPONENTS 633 Using one or more instances of the ScrollPane component in your movie will add 21KB to the SWF if no other components share the load. In this example, there’s no need for ActionScript. 1. Open the ScrollPane.fla file in this chapter’s Exercise folder. Select the ScrollPane instance, and click the Parameters tab of the Component Inspector panel. 2. In the Component Parameters area, double-click the right column of the source row. Type Redleaves.jpg. 3. Test the movie. Pretty slick! The source parameter can be pointed to any file format that Flash can load dynamically, including JPEGs, GIFs, PNGs, and other SWFs. Slider component The Slider component is conceptually the same thing as NumericStepper, except that instead of clicking buttons to advance from one number to the next, the user drags a knob along a slider, as shown in Figure 11-25. You, as designer, are responsible for setting the minimum and maximum values, and this component lets you specify whether sliding is smooth or snaps to increments specified by you. Figure 11-25. Slider lets the user drag a handle back and forth to specify a value. Slider has no text elements, so styling is fairly light. What’s there works as it does for the Button component. Skinning also works as it does for Button: double-click a Slider instance in the authoring environment to change the knob and track skins. Using one or more instances of the Slider component in your movie will add 17KB to the SWF if no other components share the load. To see how the Slider component works, open the Slider.fla file in this chapter’s Exercise folder. Note that the instance name for the Slider instance is slider, which works only because ActionScript is a case-sensitive language. You couldn’t call it Slider, because that’s the name of the class that defines this object. Also note the instance names circle1 and circle2 on the two circles. You’re about to wire up the Slider component to adjust their width and height. Click into frame 1 of the scripts layer, and type the following ActionScript: www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 11 634 slider.addEventListener(Event.CHANGE, changeHandler); function changeHandler(evt:Event):void { circle1.scaleX = slider.value / 100; circle2.scaleY = slider.value / 100; }; When the Event.CHANGE event is dispatched—this happens as the knob moves along the track—the slider’s value property is used to update scaling properties of the circle movie clips. Why divide by 100? In movie clip scaling, 0 percent is 0 and 100 percent is 1. Because the Slider instance happens to have its maximum parameter set to 100, the division puts value into the desired range, as shown in Figure 11-26. Figure 11-26. A single Slider instance can adjust many objects. Hey, that looks like a face! Be sure to experiment with the parameters in the Properties panel’s Component Parameters area. Most of them are intuitive, but liveDragging and snapInterval might not be. The liveDragging parameter tells Slider whether to update its value property as the knob moves, as opposed to when it is released. When you set liveDragging to false (deselected), the circles will resize only after you reposition the knob and then release it. The snapInterval parameter tells Slider how often to update its value property. To demonstrate, set liveDragging to true (a check mark), and then change snapInterval to a small number, such as 1. When you drag the knob, you’ll see the circles resize smoothly. Change snapInterval to 10 and test again, and the circles resize less smoothly, because you’re asking value to count by tens. You may be surprised to find a direction parameter (its values are horizontal and vertical). Why not just use the Free Transform tool to rotate this slider? Well, try it. We’ll wait .that’s kind of weird, right? It doesn’t work. Components are a sophisticated phenomenon, even though they look so simple. Now, what if you want a slanted slider, not horizontal or vertical? Here’s a trick: select the Slider instance, convert it to a movie clip (Modify ➤ Convert to Symbol), and give that movie clip an instance name such as sliderClip. When both the movie clip and its nested Slider have instance names, you’re set. sliderClip.slider.addEventListener(Event.CHANGE, changeHandler); function changeHandler(evt:Event):void { circle1.scaleX = sliderClip.slider.value / 100; circle2.scaleY = sliderClip.slider.value / 100; }; www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. BUILDING INTERFACES WITH THE UI COMPONENTS 635 TextArea component Chapter 6 introduced you to text fields and containers. Consider the TextArea component a text field in a tux. It has an attractive, slightly beveled border, lets you limit how many characters can be typed into it (like input text fields), and is optionally scrollable (see Figure 11-27). This component is akin to the <textarea> element in HTML. Figure 11-27. TextArea is the James Bond of text fields. TextArea is skinnable, but the parts are few. You’ll see a nested skin for the scrollbars when you double- click an instance in the authoring environment. More likely, you’ll want to style its text contents, which works as described in the “Button component” section. Using one or more instances of the TextArea component in your movie will add 21KB to the SWF if no other components (other than the automatically included UIScrollBar) share the load. Open the TextArea.fla file in this chapter’s Exercise folder to see an example of populating a TextArea instance with text. (We figured it would be cruel to make you type in a lengthy bit of sample text on your own.) Note that the TextArea component can display HTML text, as shown in the sample file, or plain text. Use the component’s ActionScript htmlText or text properties accordingly. Notice that the Component Parameters tab of the Properties panel shows only a text parameter for supplying text. We can’t imagine anyone using that tiny space to enter more than a sentence, so reference that parameter as a property in your ActionScript. Assuming ta is the TextArea component’s instance name, here’s the code: www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 11 636 ta.htmlText = "<p>HTML text here, with styling."; or it could look like this: ta.text = "Plain text content here."; TextInput component The TextInput component is the single-line kid brother of TextArea. For this reason, to trump it up, we’ll show it displaying one of the shortest short stories in the world, attributed to Ernest Hemingway (see Figure 11-28). Figure 11-28. TextInput is a single-line component, mainly used for user input. TextInput is primarily used to collect typed user input, like HTML-based “Contact Us” forms, and can even be set to display password characters as asterisks (see the displayAsPassword parameter). The component is skinnable—just double-click an instance in the authoring environment—but there’s not much to skin. Styling works as described in the “Button component” section. Using one or more instances of the TextInput component in your movie will add 15KB to the SWF if no other components share the load. To see the TextInput component in action, open the TextInput.fla file that accompanies this chapter. Note the two TextInput instances, with instance names input (top) and output (bottom). Select each component in turn, and look at the Parameters tab of the Component Inspector panel as you do. For the top TextInput instance, the displayAsPassword and editable parameters are set to true. For the bottom one, both of those parameters are set to false. You’re about to make the upper component reveal its password to the lower one. Click into frame 1 of the scripts layer, and type the following ActionScript: input.addEventListener(Event.CHANGE, changeHandler); function changeHandler(evt:Event):void { output.text = input.text; }; As text is typed into the upper TextInput instance, the Event.CHANGE handler updates the lower instance’s text content with that of the upper instance’s content. Because of the parameter settings, the text content is hidden above but clearly displayed below. www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. BUILDING INTERFACES WITH THE UI COMPONENTS 637 TileList component TileList is not unlike the ScrollPane component. Both load files for display, optionally with scrollbars, but TileList displays numerous files—JPEGs, SWFs, and so on—in the tiled arrangement shown in Figure 11-29. Double-click a TileList instance to edit its skins. You’ll see a second tier of skins for the scrollbars. Styling may be accomplished as described in the “Button component” section. Using one or more instances of the TileList component in your movie will add 32KB to the SWF if no other components share the load. Figure 11-29. TileList displays a tiled arrangement of content, optionally scrolling as necessary. Quite a few parameters are listed in the Component Parameters area of the Properties panel for this component, but they’re all easy to grasp. For example, there are settings for the width and number of columns, height and number of rows, direction or orientation (horizontal or vertical), and scrolling settings (on, off, and auto, the last of which makes scrollbars show only as necessary). The dataProvider parameter is the most important, because that’s where you define the content to show. It works the same as the dataProvider for ComboBox, except that instead of label and data properties, TileList expects label and source. If you find the Component Parameters a bit confining, you can always use ActionScript to add items to the TileList. To try this, open the TileList.fla file in the Chapter 11 Exercise folder. Note that the www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 11 638 TileList instance has the instance name tl, and the dynamic text field below it has the instance name output. Click into frame 1 of the scripts layer, and type the following ActionScript: tl.addItem({label:"Mug 6", source:"Mug06.jpg"}); tl.addItem({label:"Mug 7", source:"Mug07.jpg"}); tl.addItem({label:"Mug 8", source:"Mug08.jpg"}); tl.addEventListener(Event.CHANGE, changeHandler); function changeHandler(evt:Event):void { output.text = tl.selectedItem.label; }; The first three lines use practically the same approach we used for adding an additional item to the ComboBox instance in that section of the chapter. Mugs 1 through 5 are specified in the Properties panel. Here, these three lines of code give us a few more mug shots (heh, mug shots—we love that joke). In the event handler, the changeHandler() function updates the output text fields’ text property with the label value of the TileList’s selected item. TileList also supports multiple selections, like the List component. The sample code in the “List component” section provides the same basic mechanism you would use here, except instead of targeting the data property, you’ll probably want to target label , as shown in the preceding single-selection sample. UILoader component If the Flash CS5 UI components all went to a Halloween party, UILoader would show up as the Invisible Man (see Figure 11-30). Figure 11-30. Practically speaking, UILoader has no visual elements (and yes, this figure is empty; being able to include it cracks us up). www.zshareall.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... 2 Select File ➤ Save As to open the Save As dialog box Open the Format drop-down menu, and select Flash CS5 Uncompressed Document (*.xfl), as shown in Figure 12-9 The first two formats are the traditional fla file format which we have been working with since Flash first appeared Double-click an fla, and Flash launches The uncompressed document is an exploded view of the fla It will create a number... can use to change the Flash document without ever having to use Flash The most important file, as you will see in a moment, is the xfl document Doubleclick it, and Flash will open Conversely, it can be opened in Dreamweaver CS5 or other code editor, and the codie gets to play with XML When the codie saves the document, the designer simply needs to double-click the xfl document, and Flash will launch Figure... based on an XML document Next, though, we want to show you a new XML-based Flash file format called XFL that is going to have the codies drooling on their keyboards Your turn: time to explore XFL To this point in the chapter you have seen how XML can be used to manage data in a Flash document Now let’s turn our attention to using XML to build and edit a Flash document without using Flash Over the past... XML method called parent(), and the for each in statement: for each ( var node:XML in xmlDoc author.(descendants() == "Keith Peters" ) ) { trace( node.parent().parent().@title ); } The for each in statement was introduced to ActionScript 3.0 thanks to the E4X specification A similar ActionScript statement, for in, has been available for quite some time You point for in at an object, and it loops through... even 5,000 books into the document The decision is to start with books from friends of ED, and he decides to start with: ActionScript 3.0 Image Effects, Flash Applications for Mobile Devices, ActionScript for Animation, Foundation ActionScript 3.0, and Flash Math Creativity Each book has its own page count, author, and publisher Where to begin? Let’s take a look Every XML document must have at least... step—adding a title—seems obvious enough: ActionScript 3.0 Image Effects Flash Applications for Mobile Devices ActionScript for Animation Foundation ActionScript 3.0 Flash Math Creativity The difference here is that the... content), and the and tags contain XML element nodes (that is, descriptive tags) It doesn’t take much effort to connect the rest of the dots An excerpt of the completed document might look something like this: Flash Applications for Mobile Devices friendsofED 663 pages Actually, that... added to this folder must be loaded into the Flash library before they will appear 6 Open the DOMDocument.xml file in Dreamweaver CS5 or a text editor Take a minute to review the file You will discover it is broken into sections that follow the structure of the Flash file This file is at the heart of the entire XFL file format The really neat thing about this document is it can be edited, and the changes... file XML in Flash has had a rather rocky relationship simply because, until a couple of years ago, it was right up there with beating yourself in the head with a brick Things have changed, significantly for the better The ActionScript required for loading an XML document isn’t complicated You’ll need an instance of the XML and URLLoader classes, and, of course, an XML document In our case, the document... structure You will notice that there is a file called DOMDocument.xml This file is the key Inside it you will see all of the information, presented as XML, for your document including timelines, actions, motion paths, and so on When you first open it, the document won’t seem to make much sense We’ll get you over that first impression because the code in this document can be edited and saved When you do that, . ActionScript 3.0 Image Effects, Flash Applications for Mobile Devices, ActionScript for Animation, Foundation ActionScript 3.0, and Flash Math Creativity. Each. excerpt of the completed document might look something like this: <flashbooks> <book> <title> Flash Applications for Mobile Devices </title>

Ngày đăng: 15/12/2013, 01:16

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan