Tài liệu Flash: ActionScript Language Reference- P10 ppt

100 243 0
Tài liệu Flash: ActionScript Language Reference- P10 ppt

Đ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

TextField.onChanged 901 TextField.onChanged Availability Flash Player 6. Usage my_txt.onChanged = function(){ // your statements here } myListenerObj.onChanged = function(){ // your statements here } Parameters None. Returns The instance name of the text field. Description Event handler/listener; invoked when the content of a text field changes. By default, it is undefined; you can define it in a script. A reference to the text field instance is passed as a parameter to the onChanged handler. You can capture this data by putting a parameter in the event handler method. For example, the following code uses textfield_txt as the parameter that is passed to the onChanged event handler. The parameter is then used in a trace() statement to send the instance name of the text field to the Output panel: this.createTextField("myInputText_txt", 99, 10, 10, 300, 20); myInputText_txt.border = true; myInputText_txt.type = "input"; myInputText_txt.onChanged = function(textfield_txt:TextField) { trace("the value of "+textfield_txt._name+" was changed. New value is: "+textfield_txt.text); }; The onChanged handler is fired only when the change results from user interaction; for example, when the user is typing something on the keyboard, changing something in the text field using the mouse, or selecting a menu item. Programmatic changes to the text field do not trigger the onChanged event because the code recognizes changes that are made to the text field. 902 Chapter 2: ActionScript Language Reference TextField.onKillFocus Availability Flash Player 6. Usage my_txt.onKillFocus = function(newFocus:Object){ // your statements here } Parameters newFocus The object that is receiving the focus. Returns Nothing. Description Event handler; invoked when a text field loses keyboard focus. The onKillFocus method receives one parameter, newFocus , which is an object representing the new object receiving the focus. If no object receives the focus, newFocus contains the value null . Example The following example creates two text fields called first_txt and second_txt . When you give focus to a text field, information about the text field with current focus and the text field that lost focus is displayed in the Output panel. this.createTextField("first_txt", 1, 10, 10, 300, 20); first_txt.border = true; first_txt.type = "input"; this.createTextField("second_txt", 2, 10, 40, 300, 20); second_txt.border = true; second_txt.type = "input"; first_txt.onKillFocus = function(newFocus:Object) { trace(this._name+" lost focus. New focus changed to: "+newFocus._name); }; first_txt.onSetFocus = function(oldFocus:Object) { trace(this._name+" gained focus. Old focus changed from: "+oldFocus._name); } See Also TextField.onSetFocus TextField.onScroller 903 TextField.onScroller Availability Flash Player 6. Usage my_txt.onScroller = function(textFieldInstance:TextField){ // your statements here } myListenerObj.onScroller = function(textFieldInstance:TextField){ // your statements here } Parameters textFieldInstance A reference to the TextField object whose scroll position was changed. Returns Nothing. Description Event handler/listener; invoked when one of the text field scroll properties changes. A reference to the text field instance is passed as a parameter to the onScroller handler. You can capture this data by putting a parameter in the event handler method. For example, the following code uses my_txt as the parameter that is passed to the onScroller event handler. The parameter is then used in a trace() statement to send the instance name of the text field to the Output panel. myTextField.onScroller = function (my_txt:TextField) { trace (my_txt._name + " scrolled"); }; The TextField.onScroller event handler is commonly used to implement scroll bars. Scroll bars typically have a thumb or other indicator that shows the current horizontal or vertical scrolling position in a text field. Text fields can be navigated using the mouse and keyboard, which causes the scroll position to change. The scroll bar code needs to be notified if the scroll position changes because of such user interaction, which is what TextField.onScroller is used for. onScroller is called whether the scroll position changed because of a users interaction with the text field, or programmatic changes. The onChanged handler fires only if a user interaction causes the change. These two options are necessary because often one piece of code changes the scrolling position, while the scroll bar code is unrelated and won't know that the scroll position changed without being notified. 904 Chapter 2: ActionScript Language Reference Example The following example creates a text field called my_txt , and uses two buttons called scrollUp_btn and scrollDown_btn to scroll the contents of the text field. When the onScroller event handler is called, a trace statement is used to display information in the Output panel. Create two buttons with instance names scrollUp_btn and scrollDown_btn, and add the following ActionScript to your FLA or AS file: this.createTextField("scroll_txt", this.getNextHighestDepth(), 10, 10, 160, 20); this.createTextField("my_txt", this.getNextHighestDepth(), 10, 30, 320, 240); my_txt.multiline = true; my_txt.wordWrap = true; for (var i = 0; i<10; i++) { my_txt.text += "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat."; } scrollUp_btn.onRelease = function() { my_txt.scroll--; }; scrollDown_btn.onRelease = function() { my_txt.scroll++; }; my_txt.onScroller = function() { trace("onScroller called"); scroll_txt.text = my_txt.scroll+" of "+my_txt.maxscroll; }; See also TextField.hscroll, TextField.maxhscroll, TextField.maxscroll, TextField.scroll TextField.onSetFocus 905 TextField.onSetFocus Availability Flash Player 6. Usage my_txt.onSetFocus = function(oldFocus:Object){ // your statements here } Parameters oldFocus The object to lose focus. Returns Nothing. Description Event handler; invoked when a text field receives keyboard focus. The oldFocus parameter is the object that loses the focus. For example, if the user presses the Tab key to move the input focus from a button to a text field, oldFocus contains the text field instance. If there is no previously focused object, oldFocus contains a null value. Example See the example for TextField.onKillFocus. See Also TextField.onKillFocus 906 Chapter 2: ActionScript Language Reference TextField._parent Availability Flash Player 6. Usage my_txt._parent.property _parent.property Description Property; a reference to the movie clip or object that contains the current text field or object. The current object is the one containing the ActionScript code that references _parent . Use _parent to specify a relative path to movie clips or objects that are above the current text field. You can use _parent to climb up multiple levels in the display list as in the following: _parent._parent._alpha = 20; Example The following ActionScript creates two text fields and outputs information about the _parent of each object. The first text field, first_txt , is created on the main Timeline. The second text field, second_txt , is created inside the movie clip called holder_mc . this.createTextField("first_txt", this.getNextHighestDepth(), 10, 10, 160, 22); first_txt.border = true; trace(first_txt._name+"'s _parent is: "+first_txt._parent); this.createEmptyMovieClip("holder_mc", this.getNextHighestDepth()); holder_mc.createTextField("second_txt", holder_mc.getNextHighestDepth(), 10, 40, 160, 22); holder_mc.second_txt.border = true; trace(holder_mc.second_txt._name+"'s _parent is: "+holder_mc.second_txt._parent); The following information is displayed in the Output panel: first_txt's _parent is: _level0 second_txt's _parent is: _level0.holder_mc See also Button._parent, MovieClip._parent, _root, targetPath() TextField.password 907 TextField.password Availability Flash Player 6. Usage my_txt.password:Boolean Description Property; if the value of password is true , the text field is a password text field and hides the input characters using asterisks instead of the actual characters. If false , the text field is not a password text field. When password mode is enabled, the Cut and Copy commands and their corresponding keyboard accelerators will not function. This security mechanism prevents an unscrupulous user from using the shortcuts to discover a password on an unattended computer. Example The following example creates two text fields: username_txt and password_txt . Text is entered into both text fields; however, password_txt has the password property set to true . Therefore, the characters display as asterisks instead of as characters in the password_txt field. this.createTextField("username_txt", this.getNextHighestDepth(), 10, 10, 100, 22); username_txt.border = true; username_txt.type = "input"; username_txt.maxChars = 16; username_txt.text = "hello"; this.createTextField("password_txt", this.getNextHighestDepth(), 10, 40, 100, 22); password_txt.border = true; password_txt.type = "input"; password_txt.maxChars = 16; password_txt.password = true; password_txt.text = "world"; 908 Chapter 2: ActionScript Language Reference TextField._quality Availability Flash Player 6. Usage my_txt._quality:String Description Property (global); sets or retrieves the rendering quality used for a SWF file. Device fonts are always aliased and, therefore, are unaffected by the _quality property. Note: Although you can specify this property for a TextField object, it is actually a global property, and you can specify its value simply as _quality . For more information, see the _quality property. The _quality property can be set to the following values: • "LOW" Low rendering quality. Graphics are not anti-aliased, and bitmaps are not smoothed. • "MEDIUM" Medium rendering quality. Graphics are anti-aliased using a 2 x 2 pixel grid, but bitmaps are not smoothed. Suitable for movies that do not contain text. • "HIGH" High rendering quality. Graphics are anti-aliased using a 4 x 4 pixel grid, and bitmaps are smoothed if the movie is static. This is the default rendering quality setting used by Flash. • "BEST" Very high rendering quality. Graphics are anti-aliased using a 4 x 4 pixel grid and bitmaps are always smoothed. Example The following example sets the rendering quality to LOW : my_txt._quality = "LOW"; TextField.removeListener() 909 TextField.removeListener() Availability Flash Player 6. Usage my_txt.removeListener(listener:Object) Parameters listener The object that will no longer receive notifications from TextFie l d . o n C h a n g e d or TextField.onScroller. Returns If listener was successfully removed, the method returns a true value. If listener was not successfully removed (for example, if listener was not on the TextField object’s listener list), the method returns a value of false . Description Method; removes a listener object previously registered to a text field instance with TextField.addListener(). Example The following example creates an input text field called my_txt . When the user types into the field, information about the number of characters in the text field is displayed in the Output panel. If the user clicks the removeListener_btn instance, then the listener is removed and information is no longer displayed. this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 160, 20); my_txt.border = true; my_txt.type = "input"; var txtListener:Object = new Object(); txtListener.onChanged = function(textfield_txt:TextField) { trace(textfield_txt+" changed. Current length is: "+textfield_txt.length); }; my_txt.addListener(txtListener); removeListener_btn.onRelease = function() { trace("Removing listener ."); if (!my_txt.removeListener(txtListener)) { trace("Error! Unable to remove listener"); } }; 910 Chapter 2: ActionScript Language Reference TextField.removeTextField() Availability Flash Player 6. Usage my_txt.removeTextField() : Void Description Method; removes the text field specified by my_txt . This operation can only be performed on a text field that was created with MovieClip.createTextField(). When you call this method, the text field is removed. This method is similar to MovieClip.removeMovieClip() . Example The following example creates a text field that you can remove from the Stage when you click the remove_btn instance. Create a button and call it remove_btn , and then add the following ActionScript to your FLA or AS file. this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 300, 22); my_txt.text = new Date().toString(); my_txt.border = true; remove_btn.onRelease = function() { my_txt.removeTextField(); }; [...]... symbol:String = "@"; var symbolPos:Number = my_txt.text.indexOf(symbol); if (symbolPos>-1) { my_txt.replaceText(0, symbolPos, "bird"); } else { trace("symbol '"+symbol+"' not found."); } 912 Chapter 2: ActionScript Language Reference TextField.restrict Availability Flash Player 6 Usage my_txt.restrict:String Description Property; indicates the set of characters that a user may enter into the text field If... world"; my_txt.setTextFormat(my_fmt); my_txt._rotation = 45; Apply additional formatting for the text field using the TextFormat class See also Button._rotation, MovieClip._rotation 914 Chapter 2: ActionScript Language Reference TextField.scroll Availability Flash Player 6 Usage my_txt.scroll Description Property; defines the vertical position of text in a text field The scroll property is useful for... true; date_txt.selectable = false; var date_interval:Number = setInterval(updateTime, 500, date_txt); function updateTime(my_txt:TextField) { my_txt.text = new Date().toString(); } 916 Chapter 2: ActionScript Language Reference TextField.setNewTextFormat() Availability Flash Player 6 Usage my_txt.setNewTextFormat(textFormat:TextFormat) : Void Parameters textFormat A TextFormat object Returns Nothing... textFormat to the character at position index Usage 3: Applies the properties of the textFormat parameter to the span of text from the beginIndex parameter to the endIndex parameter 918 Chapter 2: ActionScript Language Reference Notice that any text inserted manually by the user, or replaced by means of TextField.replaceSel(), receives the text field's default formatting for new text, and not the formatting... }; styleObj.load("styles.css"); }; css2_btn.onRelease = function() { var styleObj:TextField.StyleSheet = new TextField.StyleSheet(); styleObj.onLoad = function(success:Boolean) { 920 Chapter 2: ActionScript Language Reference if (success) { news_txt.styleSheet = styleObj; news_txt.htmlText = newsText; } }; styleObj.load("styles2.css"); }; clearCss_btn.onRelease = function() { news_txt.styleSheet =... 100, 100, 22); four_txt.border = true; four_txt.type = "input"; three_txt.tabEnabled = false; three_txt.text = "tabEnabled = false;"; See also Button.tabEnabled, MovieClip.tabEnabled 922 Chapter 2: ActionScript Language Reference TextField.tabIndex Availability Flash Player 6 Usage my_txt.tabIndex:Number Parameters None Returns Nothing Description Property; lets you customize the tab ordering of objects... the same tabIndex value, the one that goes first is undefined You shouldn’t use the same tabIndex value for multiple objects Example The following ActionScript dynamically creates four text fields and assigns them to a custom tab order Add the following ActionScript to your FLA or AS file: this.createTextField("one_txt", this.getNextHighestDepth(), 10, 10, 100, 22); one_txt.border = true; one_txt.type... four_txt.type = "input"; TextField.tabIndex 923 one_txt.tabIndex = 3; two_txt.tabIndex = 1; three_txt.tabIndex = 2; four_txt.tabIndex = 4; See also Button.tabIndex, MovieClip.tabIndex 924 Chapter 2: ActionScript Language Reference TextField._target Availability Flash Player 6 Usage my_txt._target:String Description Read-only property; the target path of the text field instance specified by my_txt The _self... FACE="Times New Roman" SIZE="12" COLOR="#000000">Remember to always update your help panel. text: Remember to always update your help panel */ See also TextField.htmlText 926 Chapter 2: ActionScript Language Reference TextField.textColor Availability Flash Player 6 Usage my_txt.textColor:Number Description Property; indicates the color of the text in a text field The hexadecimal color system... Which outputs the following information: textHeight: 15, textWidth: 56 _height: 300, _width: 100 after my_txt.autoSize = true; _height: 19, _width: 60 See Also TextField.textWidth 928 Chapter 2: ActionScript Language Reference TextField.textWidth Availability Flash Player 6 Usage my_txt.textWidth:Number Description Property; indicates the width of the text Example See the example for TextField.textHeight . code recognizes changes that are made to the text field. 902 Chapter 2: ActionScript Language Reference TextField.onKillFocus Availability Flash Player 6 that the scroll position changed without being notified. 904 Chapter 2: ActionScript Language Reference Example The following example creates a text field

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

Từ khóa liên quan

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

Tài liệu liên quan