Danh mục

Dynamically Creating and Configuring Text Fields

Số trang: 15      Loại file: pdf      Dung lượng: 39.19 KB      Lượt xem: 10      Lượt tải: 0    
Jamona

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tạo và Cấu hình tự động văn bản nhập Mặc dù bạn đang trình bày với một loạt các lựa chọn khi tạo và cấu hình các trường văn bản trong môi trường authoring, có thể tạo ra các lĩnh vực văn bản trên fly-trong khi phim của bạn đang chạy, cho phép bạn kiểm soát lớn hơn trong dự án của bạn cách xử lý văn bản. Chúng ta hãy nhìn vào quá trình tạo năng động.
Nội dung trích xuất từ tài liệu:
Dynamically Creating and Configuring Text Fields < Day Day Up >Dynamically Creating and Configuring Text FieldsAlthough youre presented with a variety of options when creating and configuring textfields in the authoring environment, being able to create text fields on the fly—whileyour movie is running—gives you even greater control over the way your project handlestext. Lets take a look at the dynamic creation process.To create a text field using ActionScript, you use the createTextField() method, asfollows:createTextField(instanceName, depth, x, y, width, height);Now note the following example, which uses the createTextField() method to create atext field:createTextField(myField_txt, 10, 20, 50, 200, 30);This script creates a text field named myField_txt, with its initial depth, x, y, width, andheight properties set as shown.Every text field, whether placed on the stage while authoring the movie or createddynamically, is considered an instance of the TextField class. As such, text fields can betreated in several ways similarly to movie clip instances. Individual text fields are giveninstance names from the Property Inspector (or when created dynamically, as shown inthe preceding code). When targeting a text field instance with a script, you use its targetpath, which includes its instance name.You may not be able to tell by looking at the Actions toolbox in the Actions panel, butseveral methods—similar to Movie Clip object methods—are available to text fieldinstances. For example, this script makes the myField_txt text field draggable:startDrag(myField_txt, true);Unlike movie clips, text fields are not timelines; therefore, certain methods such asprevFrame(), attachMovie(), loadMovie(), and so on have no meaning when used in thecontext of a text field instance.Text field instances have several properties similar to those of movie clips. For example,myField_txt._alpha = 50;makes the myField_txt text field 50 percent transparent. With a little bit ofexperimentation, youll be able to see which methods and properties are shared by movieclip and text field instances.In addition to the properties and methods discussed thus far, text fields have numerousunique methods and properties for manipulating and controlling text within the text field(rather than the text field itself, as previously discussed). Several of these methods areemployed to format text-field text using TextFormat and Cascading Style Sheet (CSS)objects—well save our discussion of those for the later sections of this lesson. In themeantime, lets look at a couple of useful methods that dont pertain to formatting.To remove a text field instance that was created dynamically, use the removeTextField()method in the following manner:myField_txt.removeTextField();This script removes the text field named myField_txt.NOTEOnly text fields created dynamically can be removed using this method. Text fieldsplaced on the stage while authoring your movie cannot be removed in this way.Two of the most common actions you can perform in conjunction with text fields areadding and deleting text—both of which can use the replaceSel() method. You caninvoke this method to replace the currently selected text with anything you define.In the following example, assume that the myField_txt text field contains the text, I lovemy dog and cat very much! Then assume that the dog and cat portion of the text hasbeen selected. You can use the replaceSel() method, as shown in the following code, toreplace that text:myField_txt.replaceSel(bird and snake);The myField_txt text field now reads, I love my bird and snake very much!The value placed within the replaceSel() method when its invoked can be a string of text,an empty string (), or even a variable.As mentioned earlier in this lesson, text fields have numerous properties that you canconfigure using ActionScript while the movie is playing. These properties affect not onlythe way the field looks and reacts to text, but how it functions. Some of these propertiesare familiar because weve already used and discussed them; others dont warrant muchdiscussion because they do the same thing as the corresponding properties that you setwith the Property Inspector when creating a text field in the authoring environment. Forexample, consider the selectable property. You would use the following syntax to makethe text in the myField_txt text field instance selectable:myField_txt.selectable = true;Now lets review some of the less obvious properties of text field instances: • autoSize. This property determines whether a text field expands and contracts its borders automatically to accommodate the amount of text it contains. A text fields width and height are normally set using static (unchanging) values. The AutoSize property allows a text fields size to be dynamic—that is, determined by the text thats typed into it. • borderColor. This property represents the color of the border around a text field. You can set it using a hex value: • • myField_txt.borderColor = 0x336699; • Setting the border color has no visible effect unless the border itself is visible: myField_txt.border = true; The same logic applies to the background and backgroundColor properties. • bottomScroll. This read-only property represents the line number of the bottom- most visible line of text in a text field.• hscroll. This property is a numeric value representing in points the current horizontal scrolling position. If the hscroll property of a text field is set to anything greater than 0, all the text is shifted to the left. With a setting of 10, for example, the text is left-shifted by 10 points. This property cannot be set to a value higher ...

Tài liệu được xem nhiều: