"Change the scale, background color, or frame frequency of the output SWF"
Right-click your item in the "Navigator" window frame > select "Properties" > select "ActionScript Compiler" > in "Additional Compiler arguments" Enter the command you need.
To change the background color, please enter:-default-background-color 0xffffff
"Mouse coordinates"
MouseX Mousey
"Check variable type and return boolean value"
Is
"Check variable type and return type"
typeof
"Check the object type and return the object"
As
"is a number but not a valid number problem"
var quantity:number =-"rabbits";
Trace (typeof quantity); Display: "Number", but it is Nan (not a number)
Trace (quantity is number); True
Trace (quantity!= NaN); False
Use the isNaN () function to detect:
isNaN (quantity); True
Detect whether a variable contains a valid number:
!isnan (quantity); False
"Cancel the default strict compilation mode"
Right-click your item in the "Navigator" window frame > select "Properties" > select "ActionScript Compiler" > Cancel "enabel compile-time type checking" option
"Primitive data types and complex data types are like" value type "and" reference type "
Primitive data types are similar to passing by value:
var intone:int = 1;
var inttwo:int = 1;
Trace (intone = = Inttwo); True
"Complex data types are like passing by reference"
var arrayone:array = new Array ("A", "B");
var arraytwo:array = Arrayone;
Trace (Arrayone = = Arraytwo); True
//-----------------------------------
var arrayone:array = new Array ("A", "B");
var arraytwo:array = new Array ("A", "B");
Trace (Arrayone = = Arraytwo); False
"Optimized logical AND (&&) and OR (| |) of small Knowledge "
For logical AND (&&):
ActionScript does not calculate the second half of the logical AND operator unless the first half of the conditional expression is true. If the first half is false, the entire conditional expression must be false, so the second half of the formula is not efficient.
For logical OR (| |):
Unless the first half of the conditional expression is false, ActionScript does not calculate the second half of the logical OR operator, and if the first half is true, the entire conditional expression must be true.
Summary: When using a logical and (&&), put the expression that is most likely to be false to precede; use logical OR (| |) , the expression that is most likely to be true is placed ahead.
"Timer class Considerations"
Do not think timer can be extremely accurate; Use timer interval not less than 10 milliseconds.
"Private,protected,internal,public access Rights"
Private: can only be accessed within the class itself, by convention, by naming private members with the underscore "_" beginning;
Protected: Can be accessed by the class itself or by any child class. But this is based on an instance. In other words, a class instance can access its own protected member or a protected member of a parent class, but it cannot access the protected members of other instances of the same class, and by convention, the name of the protected member begins with an underscore "_";
Internal: Can be accessed by the class itself or by any class within the same package;
Public: can be accessed within a class, or by a class instance, or as static, and can be accessed directly from the class.
"A function has an unknown number of arguments, using the arguments object or the" ... (rest) "symbol to access its arguments"
Note: Use the "... (rest) parameter makes the arguments object unavailable;
Private Funciton average (): void{
Trace (arguments.length); Number of output parameters
The arguments type is: object, but it can be accessed like an array.
Trace (arguments[1]); Output second parameter
}
Private function average (... argu): void{
Trace (argu[1]); The second parameter is output, and the Argu parameter name is custom.
}
"Error Handling Try,catch,finally"
Private Function Tryerror (): void{
try {
Trace ("Test begins-try");
ThrowError ();
}catch (errobject:error) {
Trace ("error message:" + errobject.message);
Trace ("Test over-catch");
Return
}finally{
Trace ("Although the return method is already in the catch, the code in the finally that is behind the return method will still be executed." In fact, whether the return method is in a try or catch, the finally code will always be executed ");
}
Trace ("The return is already in front of you, and this is not going to be done here.) unless no error is thrown so that the code in the catch is not executed";
}
Private Function ThrowError (): void{
throw new error ("Throw error");
}
"The difference between for...in and for Each...in"
Unlike the for...in loop, the iteration variable in the for Each...in loop contains the value saved by the property, not the name (or primary key, index) of the property.
"Tips for naming package paths"
It is better to use the name of the package that corresponds to the owner and the related project. Traditionally, the name of the package should begin with a reverse URL name. For example, if Example Corp. wrote some ActionScript3.0 classes, All classes are placed inside the Com.examplecorp package (or in the Com.examplecorp package). So if there is another Example Corp. (examplecorp.co.uk) in the UK Also wrote a number of ActionScript3.0 classes, as long as the use of packet Uk.co.examplecorp, you can ensure uniqueness.
When a class is part of a particular application, it should be placed inside the application-specific child package. For example, Example The corp may have an application named Widgetstore. If the Widgetstore application uses a class called Applicationmanager, this class should be placed in the Com.examplecorp.widgetstore package. Or in the child package of the package.
By convention, the package name begins with a lowercase letter.
"Implicit removal method (getter) and set method (setter)"
Public function Get count (): UINT {
return _count;
}
Public function set COUNT (value:uint): UINT {
if (value < 100) {
_count = value;
}else {
Throw Error ();
}
}
"Make sure the class is never going to have a subclass, use final"
Final public class example{}
"Use of Super keywords"
Super (); The constructor of the parent class, which can only be used inside a class instance constructor
Super.propertyname; Call the properties of the parent class, the property needs to be declared public or protected
Super.methodname (); Calling methods of the parent class, which need to be declared public or protected
"Create constants, use keyword const instead of var"
static Public Const Example:string = "EXAMPLE";
"Detect player Version"
Flash.system.Capabilities.version
This method does not apply to any Flash Player versions prior to version 8.5.
"Judge the client system"
Flash.system.Capabilities.os
"Detect player Type"
Flash.system.Capabilities.playerType
The possible values are:
"StandAlone" for standalone Flash Player
"External" for external Flash Player or in test mode
"PlugIn" for Flash Player browser plugin
"ActiveX" Flash Player ActiveX Control for use by Microsoft Internet Explorer
"Detection System language"
Flash.system.Capabilities.language
"Determines whether the user has IME enabled (Input Method Editor)
Flash.system.IME.enabled
"Detect screen Resolution"
Flash.system.Capabilities.screenResolutionX
Flash.system.Capabilities.screenResolutionY
"The algorithm to center the pop-up window"
X = (stage width/2)-(window width/2)
Y = (stage height/2)-(window height/2)
"Control how the movie fits the player, including scaling issues"
Stage.scalemode
Alternative values: Flash.display.StageScaleMode
"Alignment of the stage"
Stage.align
Alternative values: flash.display.StageAlign
"Hide Flash Player's right-click menu"
Stage.showdefaultcontextmenu = false;
"Detect if the system has audio features"
Flash.system.Capabilities.hasAudio
"Detects whether the player is running on a system with a MP3 decoder or on a system that does not have a MP3 decoder"
Flash.system.Capabilities.hasMP3
"Detect whether the player can (true) or not (false) play streaming video"
Flash.system.Capabilities.hasStreamingVideo
"Detect whether the player is running on a system that supports (true) embedded video or on a system that does not support (false) embedded video"
Flash.system.Capabilities.hasEmbeddedVideo
"Detect whether the player can (true) or not (false) encode a video stream (such as a video stream from a Web camera)"
Flash.system.Capabilities.hasVideoEncoder
"Show the security Settings panel in Flash Player"
Flash.system.Security.showSettings ();
Available options: Flash.system.SecurityPanel
"Let the. swf of the other domain access the. swf" of this domain
In the. swf file in this domain, add: flash.system.Security.allowDomain ()
Or use the security policy file "Crossdomain.xml". Before Flash 8, this file must be placed in the root directory of the. swf's domain, and now you can use Flash.system.Security.loadPolicyFile (), Specifies the location where the security policy file is located. Denying any domain is done in the <cross-domain-policy> tab, and the security policy file also supports the common character "*":
<?xml version= "1.0"?>
<!--Http://www.mydomain.com/crossdomain.xml-->
<cross-domain-policy>
<allow-access-from domain= "www.riahome.cn"/>
<allow-access-from domain= "*. Y-boy.cn "/>
<allow-access-from domain= "210.38.196.48"/>
<allow-access-from domain= "*"/>
</cross-domain-policy>
"Conversion of numbers to different systems"
parseint (str:string, radix:uint = 0): Number returns decimal, parameter radix represents the cardinality of the number to parse. If you omit radix, the default is 10 unless the string starts with "0x", "0X" or "0":
Trace (parseint ("0x12")); Set radix to 16, output: 18
Trace (parseint ("017")); Set Radix to 8, output: 15
or use the ToString (radix) method of the Number,uint and int objects.
"Use Math.Round () to rounding a number, rounded"
Math.Round ()
Trace (Math.Round (204.499)); Output: 204
Trace (Math.Round (401.5)); Output: 402
"Use Math.floor () to get a number down, as long as the integer part ignores the decimal point."
Trace (Math.floor (204.99)); Output: 204
"Use Math.ceil () to round up a number, as long as the decimal part is Non-zero, and the integer part adds 1"
Trace (Math.ceil (401.01)); Output: 402
"Produce a random number"
Use Math.random () to produce a pseudo-random number n, where 0 <= N < 1
"Take the number to the nearest decimal point, the specified precision"
1. Determine the number of decimal places you want to take: for example, if you want to take 90.337 to 90.34, it means you want to take to two decimal places, that is, you want to take to the nearest 0.01;
2. Let the input value be divided by the number selected in step 1 (this example is 0.01);
3. Use Math.Round () to take the value of step 2 into the nearest integer;
4. Multiply the result of step 3 by the value of Step 2 for division.
For example, to take 90.337 to two decimal places, you can use:
Trace (Math.Round (90.337/0.01) *0.01); Output: 90.34
"The nearest value to the number of integers."
Example 1, which takes 92.5 to the nearest value of 5:
Trace (Math.Round (92.5/5) *5); Output: 95
Example 2, which takes 92.5 to the nearest value of 10:
Trace (Math.Round (92.5/10) *10); Output: 90
"Get random numbers within a specified range of values"
Desirable range: [min, Max]
Private Function Randrange (Min:number, Max:number): number {
var randomnum:number = Math.floor (Math.random () * (Max-min + 1)) + min;
return randomnum;
}
application Example:
Simulate a silver coin that expects to get a random Boolean value (True or FALSE): Randrange (0, 1);
Simulate the dice, that is, want to get a random six values: Randrange (1, 6);
The best way to avoid being cached is to generate a unique number appended to the end of the URL, usually by obtaining the current number of milliseconds.
Conversion between radians (radian) and degrees (degree)
From radians to degrees: degrees = radians * 180/math.pi
Convert from degree to radian: radians = degrees * math.pi/180
"Calculate the distance between two points."
Pythagorean Theorem: c2 = a2 + b2
Assuming there are two movie clips MC1 and MC2, the distance between their two points is C:
var c:number = math.sqrt (Math.pow (mc1.x-mc2.x, 2) + Math.pow (MC1.Y-MC2.Y, 2));
"Simulate circular motion"
Known Center O (x0, y0), radius r and radians angle, find the coordinates of p (x, y) at any point on the circle:
x = x0 + (math.cos (angle) * r);
y = y0 + (Math.sin (angle) * r);
Note: The x-axis positive direction of the stage is horizontally to the right, and the Y axis is vertically downward.
"Simulated elliptical motion"
Known Center O (x0, y0), long axis A, short axis b, and radian angle, find the coordinates of p (x, y) at any point on the circle:
x = x0 + (math.cos (angle) * a);
y = y0 + (Math.sin (angle) * b);
"Conversion between Fahrenheit temperature and Celsius temperature"
Fahrenheit temperature = number of degrees Celsius * 9/5 + 32
Celsius temperature = (Fahrenheit degree-32) * 5/9
"Conversion between kilograms and pounds"
KG = pound * 2.2
LB = kg/2.2
"Add an element to the end of an array"
var array:array = new Array ();
Array.push ("A", "B");
Adding a single element to the end of an array can also do this:
Array[array.length] = "C";
If an element that is indexed does not exist, the array itself is automatically extended to contain enough elements. The element in the middle is set to undefined:
ARRAY[5] = "E";
Trace (array[4]); Output: undefined
"Add an element to the beginning of an array"
var array:array = ["A", "B"];
Array.unshift ("C", "D");
Trace (array); Output: C,d,a,b
"Deletes the first element in the array and returns the element, using the shift () method"
var letters:array = new Array ("A", "B", "C");
var firstletter:string = Letters.shift ();
Trace (Letters); Output: B,c
Trace (Firstletter); Output: A
"Deletes the last element in the array and returns the value of the element, using the Pop () method"
var letters:array = new Array ("A", "B", "C");
Trace (Letters); Output: A,b,c
var letter:string = Letters.pop ();
Trace (Letters); Output: A,b
Trace (letter); Output: C
"Deletes the elements in the array, adds new elements to the array, and returns the deleted elements, using the splice () method"
Splice (Startindex:int, Deletecount:uint, ... values): Array
StartIndex: An integer that specifies the index of the element in the array at which to begin inserting or deleting;
DeleteCount: An integer that specifies the number of elements to delete;
... values: An optional list or array of one or more values, separated by commas, that is inserted into this array at the location specified by the StartIndex parameter.
"Find the first matching element in an array"
var array:array = ["A", "B", "C", "D", "a", "B", "C", "D"];
var match:string = "B";
for (var i:int = 0; i < Array.Length; i++) {
if (array[i] = = match) {
Trace ("Element with index" + i + "found to match" + match);
Output: Element with index 1 found to match b
Break
}
}
"Find the last matching element in an array"
var array:array = ["A", "B", "C", "D", "a", "B", "C", "D"];
var match:string = "B";
for (var i:int = array.length-1 i >= 0; i--) {
if (array[i] = = match) {
Trace ("Element with index" + i + "found to match" + match);
Output: Element with index 5 found to match B
Break
}
}
"Turn Strings into groups"
Use the String.Split () method:
var list:string = "I am youngboy."
var Words:array = List.split (""); Cut a string with a space as a delimiter
Trace (words); Output: I,am,youngboy.
"Turn the array into a string"
Use the String.Join () method:
var myarr:array = new Array ("One", "two", "three");
var mystr:string = Myarr.join ("and");
Trace (Myarr); Output: One,two,three
Trace (MYSTR); Output: One and two and three
"Working with object arrays for related data"
var cars:array = new Array ();
Cars.push ({make: "Mike", year:1997, Color: "Blue"});
Cars.push ({make: "Kelly", year:1986, Color: "Red"});
for (var i:int = 0; i < cars.length; i++) {
Trace (Cars[i].make + "-" + Cars[i].year + "-" + Cars[i].color);
}
Output:
Mike-1997-blue
Kelly-1986-red
"Get minimum or maximum value in array"
var scores:array = [10, 4, 15, 8];
Scores.sort (Array.numeric);
Trace ("Minimum:" + scores[0]);
Trace ("Maximum:" + scores[scores.length-1]);
"Read the associative array element using the for ... in statement"
var myobject:object = new Object ();
Myobject.name = "Youngboy";
Myobject.age = 20;
for (Var i:string in MyObject) {
Trace (i + ":" + myobject[i]);
}
Output: Name:youngboy
Age:20
Note: The for ... in loop does not display all of the object's built-in properties. For example, looping displays special properties that are new during execution, but does not list the methods of the built-in objects, even if they are stored in object properties.
"AVM (ActionScript virtual Machine, virtual machines) and rendering engine (Rendering Engine)"
The AVM is responsible for performing ActionScript programs, while the rendering engine draws objects onto the display.
"Indicates how many objects are displayed in the display list of the container"
Each container has a Numchildren attribute.
"Add Item to display list"
AddChild (Child:displayobject)
Addchildat (Child:displayobject, Index:int)
Index: Adds the indexed position of the subkey. If you specify the index position that is currently occupied, the position and child objects at all higher positions are moved up one position in the child list.
"Remove item from Display list"
RemoveChild (Child:displayobject)
Removechildat (Index:int)
Index: The child index of the displayobject to be deleted, and any display object on top of the subkey is positioned at the index minus 1.
If you want to remove all the child components of a window, you can combine Removechildat (), Numchildren properties, and a for loop. Because the index position changes each time a child component is removed, there are two ways to handle all the removal of the child components:
1. Always remove the sub component of position 0;
2. Remove the sub component in reverse, starting from the tail end.
"Change the position of an existing subkey in the Display object container"
Setchildindex (Child:displayobject, index:int): void
Possible methods to use:
Returns the index position of the child instance of Displayobject: Getchildindex (child:displayobject): int
Returns the child display object instance at the specified index: Getchildat (index:int):D Isplayobject
Note: When a child component is moved to an index that is below its current location, then, all the child components of the index from the index until the child component index increase their index by 1, and the subassembly is assigned to the indexed index. When a child component is moved to a higher index, from the index above the child component index, Until all the child components of the marked index are reduced by 1, the child component is assigned to the index value.
"Tips on TextField the vertical way to put text on the center of a button surface"
Textfield.y = (_height-textfield.textheight)/2;
TEXTFIELD.Y-= 2; Minus 2 pixels to adjust the offset
"External. swf movie load and interact"
1. Monitor the init incident;
2. Access the downloaded video through the content attribute.
When the video is loaded with enough initialization work, the Init event is initiated when its methods and properties are receptive to interaction. The movie can be controlled only after the loader initiates the Init event. The video that was loaded has not been initialized to try to interact with it, and is going to produce errors during execution.
_loader.contentloaderinfo.addeventlistener (Event.init, handleinit); When the properties and methods of a loaded. SWF are available
_loader.load (New URLRequest ("externalmovie.swf"));
Private Function Handleinit (event:event): void {
var movie:* = _loader.content;
Trace (Movie.getcolor ());
Movie.setcolor (0xff0000);
}
There are two types of TextField: dynamic and input, and the default is dynamic. Change the TextField type method "
Field.type = Textfieldtype.input; The default value of the Selectable property is True
Flash.text.TextFieldType.INPUT and Flash.text.TextFieldType.DYNAMIC
"Filter Text Input"
Textfield.restrict = "Here is what can be entered";
Field.restrict = "^ Here for the prohibition of input content";
The Restrict property supports some styles similar to regular expressions:
Field.restrict = "A-za-z"; Only size letters allowed
Field.restrict = "A-za-z"; Only letters and spaces are allowed
Field.restrict = "0-9"; Allow only numbers
Field.restrict = "^ABCDEFG"; Except for lowercase letters ABCDEFG are not allowed, others are allowed
Field.restrict = "^a-z"; All lowercase letters are not allowed, but other content is allowed, including uppercase letters
Field.restrict = "0-9^5"; Only numbers are allowed, but 5 exceptions
Let the restrict character contain letters with special meanings (for example-and ^):
Field.restrict = "0-9\\-"; Allow numbers and dashes
Field.restrict = "0-9\\^"; Allow numbers and ^
Field.restrict = "0-9\\\\"; Allow numbers and backslashes
You can also use the Unicode escape sequence to specify what is allowed. For example:
Field.restrict = "^\u001a";
Note: ActionScript is case-sensitive, and if the Restrict property is set to ABC, allowing the uppercase form of letters (A,B and C) to be entered in lowercase (a,b and C), and vice versa. The Restrict property affects only what the user can enter, A script can put any text in a text field.
"Set the maximum length of the input box"
TextField.maxChars:int
Append content to TextField
Textfield.appendtext (text:string): void
This method is more efficient than connecting two strings (such as Field.text + = MoreText) by using an addition assignment on the Text property.
"Display HTML-formatted text"
Textfield.htmltext = "<b>html text</b>";
The supported HTML tag sets are: <b>,<i>,<u>,<font> (with face,size and color attributes),< p>,<br>,<a> <li>, and <textformat> (with leftmargin,rightmargin,blockindent,indent,leading and TabStops attributes, corresponding to TextFormat class with the same name as the property)
"Reduced whitespace"
Textfield.condensewhite = true;
Removes extra white space (spaces, line breaks, and so on) in text fields that have HTML text, as most HTML browsers do.
Note: Set the Condensewhite property before setting the HTMLText property
Auto sizing and aligning
Textfield.autosize = Textfieldautosize.left;
Optional value:
Flash.text.TextFieldAutoSize.CENTER
Flash.text.TextFieldAutoSize.LEFT
Flash.text.TextFieldAutoSize.NONE
Flash.text.TextFieldAutoSize.RIGHT
"Indicates whether text fields are wrapped automatically"
Textfield.wordwrap = true; Wrap Line
"Scrolling text with procedural means"
The horizontal direction is in pixels, and the vertical direction is in rows:
SCROLLV: Indicates the topmost line of the visible area of the text box, which can be read and written;
BOTTOMSCROLLV: Indicates the bottom of the text box visible lines, read-only;
MAXSCROLLV:SCROLLV maximum value, read only;
Numlines: Defines the number of lines of text in a multiline text field, read-only;
TEXTFIELD.SCROLLV = FIELD.MAXSCROLLV; Scroll to the last page
"Responding to scrolling events"
Field.addeventlistener (Event.scroll, Ontextscroll);
"Ways to Style text"
1. Use HTML tags for styling;
2. Use of TextFormat objects;
3. Use CSS.
For example: HTML is with <font> tag, TextFormat object is set Font property, and CSS is using font-family attribute.
Supported cascading style sheet (CSS) properties and values, and their corresponding ActionScript property names (in parentheses):
Color (color), display (display), font-family (fontFamily), Font-size (FontSize), Font-style (FontStyle), Font-weight ( FontWeight), kerning (kerning), leading (leading), letter-spacing (letterspacing), Margin-left (MarginLeft), Margin-right (MarginRight), Text-align (textAlign), Text-decoration (textdecoration), Text-indent (textindent)
Supported HTML entities: < (less than: <), > (Greater Than: >), & (and: &), "(double quote:"), ' (apostrophe, single quote: ')
The two ways in which style objects are written:
Writing a:
var samplestyle:object = new Object ();
Samplestyle.color = "#FFFFFF";
samplestyle.textalign = "center";
Css.setstyle (". Sample", Samplestyle);
Writing two:
var samplestyle:object = {color: "#FFFFFF", TextAlign: "Center"};
Css.setstyle (". Sample", Samplestyle);
"Style text entered by a user"
Using the Defaulttextformat property, the style is applied to the text that the user types into the input box:
var formatter:textformat = new TextFormat ();
Formatter.color = 0x0000ff; Turn the text into blue
Field.defaulttextformat = formatter;
"Style part of existing text"
Textformat.settextformat (Format:textformat, beginindex:int =-1, endindex:int =-1): void
"Set font for text boxes"
Example:
HTML:field.htmlText = "<font face= ' Arial ' >formatted text</font>";
TextFormat:formatter.font = "Arial";
css:p{font-family:arial;}
You can also use a comma-delimited list of fonts: Formatter.font = "Arial, Verdana, Helvetica";
Attention:
Font and font groups are different. There are three types of font groups: _sans,_serif and _typewriter.
_sans groups generally refer to the Arial or Helvetica font;
The _serif group generally refers to the times or times New Roman this font;
_typewriter groups generally refer to the Courier or Courier New Font.
"Embed Fonts"
Use [Embed] to set the label. [Embed] The label should appear in the ActionScript file, outside the class declaration. You can embed TrueType fonts or system fonts. Syntax for embedding TrueType fonts:
[Embed (source= "Pathtottffile", fontname= "FontName", mimetype= "Application/x-font-truetype")]
The path of the Pathtottffile:ttf file, the path of the TrueType font can be relative or absolute;
FontName: Font name;
Syntax for embedded system fonts:
[Embed (systemfont= "Times New Roman", fontname= "Times New Roman", mimetype= "Application/x-font-truetype")]
FontName: Use the same name as the actual system font name.
Note: When using embedded fonts, set the TextField embedfonts property to True so that TextField can only use inline fonts. If you try to set Embedfonts to true TextField use device fonts, Nothing will be shown. If Embedfonts is set to True, the list of fonts separated by commas cannot be specified.
"Create text that can rotate"
Use inline fonts. When you rotate the text box, the device font disappears.
"Show Unicode Text"
1. Loading of Unicode text from external sources;
2. If your editor supports Unicode (such as Flex Builder), you can use that character directly in your ActionScript program;
3. Using the Unicode escape character, all Unicode escape characters in ActionScript begin with a \u followed by a four-digit hexadecimal number.
Note: If you want to get Unicode characters, use under Windows: Start > All Programs > Attachments > System Tools > Character Map.
"Bring Flash Player's focus to the text box"
Stage.focus = field;
To remove focus from:
Stage.focus = null;
Note: When a. swf file is first loaded into a Web browser, there is no focus. Therefore, you must first move the focus to flash Player before assigning focus to an element of the flash application in a procedural way.
"Select text in ActionScript"
Using Textfield.setselection (Beginindex:int, endindex:int): void
In order for text to be selected correctly, the text box must have the focus:
Stage.focus = field; Set focus to the text box
Field.text = "This is example text"; Set text
Field.setselection (0, 4); Highlight the word "this"
Use the read-only Selectionbeginindex and Selectionendindex properties to access the index of the selected character range.
"Sets the placement point (cursor position) in the text and accesses the index value of the cursor position"
You can use Textfield.setselection () to set the starting and ending index parameters to the same value, and to set the cursor position in the text (assuming the focus):
Field.setselection (0, 0); Place the placement point before the first character
Trace (Field.caretindex); Index value of output cursor position
"Respond when a text field is selected or deselected"
When you get focus: focusevent.focus_in
When lost Focus: Focusevent.focus_out
When the focus is removed through the keyboard (tab): Focusevent.key_focus_change
When the focus is removed by the mouse: Focusevent.mouse_focus_change
The FocusEvent class has a Relatedobject property. For the Focus_in event, the Relatedobject property is the reference address of the object that has the focus just now; for Focus_out,key_focus_change and mouse _focus_change event, the Relatedobject property is the reference address of the object that just received the focus.
Both focus_in and Focus_out events occur after the focus has changed, so both are irrevocable events. For the Key_focus_change and Mouse_focus_change events, You can use the Focusevent.preventdefault () method to cancel the default behavior:
Field.addeventlistener (Focusevent.key_focus_change, Onkeyfocus);
Private Function Onkeyfocus (event:focusevent): void {
if (Field.text = = "") {
Event.preventdefault (); The TAB key is not allowed to remove the focus until the field has no text
}
Event.relatedobject is the reference address of the object that has the focus just now, that is, the next object that gets the focus
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.