tailieunhanh - Dynamically Creating and Configuring Text Fields

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. | Dynamically Creating and Configuring Text Fields Although you re presented with a variety of options when creating and configuring text fields in the authoring environment being able to create text fields on the fly while your movie is running gives you even greater control over the way your project handles text. Let s take a look at the dynamic creation process. To create a text field using ActionScript you use the createTextField method as follows createTextField instanceName depth x y width height Now note the following example which uses the createTextField method to create a text 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 and height properties set as shown. Every text field whether placed on the stage while authoring the movie or created dynamically is considered an instance of the TextField class. As such text fields can be treated in several ways similarly to movie clip instances. Individual text fields are given instance names from the Property Inspector or when created dynamically as shown in the preceding code . When targeting a text field instance with a script you use its target path which includes its instance name. You may not be able to tell by looking at the Actions toolbox in the Actions panel but several methods similar to Movie Clip object methods are available to text field instances. 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 as prevFrame attachMovie loadMovie and so on have no meaning when used in the context of a text field instance. Text field instances have several properties similar to those of movie clips. For example 50 makes the myField_txt text field 50 percent transparent. With a little bit of experimentation you ll be able to see which methods and properties are shared by movie clip and text field