Tài liệu Flash: ActionScript Language Reference- P11 docx

104 259 0
Tài liệu Flash: ActionScript Language Reference- P11 docx

Đ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

Video.height 1001 my_mc._height = my_mc.my_video.height; }; See also MovieClip._height, Video.width 1002 Chapter 2: ActionScript Language Reference Video.smoothing Availability Flash Player 6. Usage my_video.smoothing:Boolean Description Property; a Boolean value that specifies whether the video should be smoothed (interpolated) when it is scaled. For smoothing to work, the player must be in high-quality mode. The default value is false (no smoothing). Example The following example uses a button (called smoothing_btn ) to toggle the smoothing property that is applied to the video my_video when it plays in a SWF file. Create a button called smoothing_btn and add the following ActionScript to your FLA or AS file: this.createTextField("smoothing_txt", this.getNextHighestDepth(), 0, 0, 100, 22); smoothing_txt.autoSize = true; var my_nc:NetConnection = new NetConnection(); my_nc.connect(null); var my_ns:NetStream = new NetStream(my_nc); my_video.attachVideo(my_ns); my_ns.play("video1.flv"); my_ns.onStatus = function(infoObject:Object) { updateSmoothing(); }; smoothing_btn.onRelease = function() { my_video.smoothing = !my_video.smoothing; updateSmoothing(); }; function updateSmoothing():Void { smoothing_txt.text = "smoothing = "+my_video.smoothing; } Video.width 1003 Video.width Availability Flash Player 6. Usage my_video.width:Number Description Property (read-only); an integer specifying the width of the video stream, in pixels. For live streams, this value is the same as the Camera.width property of the Camera object that is capturing the video stream. For FLV files, this value is the width of the file that was exported as an FLV file. You may want to use this property, for example, to ensure that the user is seeing the video at the same size at which it was captured, regardless of the actual size of the Video object on the Stage. Example See the examples for Video.height. 1004 Chapter 2: ActionScript Language Reference void Availability Flash Player 5. Usage void (expression) function functionName():Void {} Description Usage 1: Operator; a unary operator that discards the expression value and returns an undefined value. The void operator is often used in comparisons using the equality ( == ) operator to test for undefined values. Usage 2: Data type; used in function definitions to indicate that a function will not return a value. Example Usage 1: In the following ActionScript, the void operator is used to test for undefined values: if (someUndefinedVariable == void (0)) { trace("someUndefinedVariable is undefined"); } The previous code can also be written in the following way: if (someUndefinedVariable == undefined) { trace("someUndefinedVariable is undefined"); } Usage 2: In the following example, a function that returns a value is defined using the Void return type, which results in a compile-time error: function myFunction():Void { return "This will cause a compile-time error."; } /* the following function call will generate a compile-time error: **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: A function with return type Void may not return a value. return "This will cause a compile-time error."; */ myFunction(); CHAPTER 2 ActionScript Language Reference while 1005 while Availability Flash Player 4. Usage while(condition) { statement(s); } Parameters condition An expression that evaluates to true or false . statement(s) The instructions to execute if the condition evaluates to true . Returns Nothing. Description Statement; evaluates a condition and if the condition evaluates to true , runs a statement or series of statements before looping back to evaluate the condition again. After the condition evaluates to false , the statement or series of statements is skipped and the loop ends. The while statement performs the following series of steps. Each repetition of steps 1 through 4 is called an iteration of the loop. The condition is retested at the beginning of each iteration, as shown in the following steps: 1. The expression condition is evaluated. 2. If condition evaluates to true or a value that converts to the Boolean value true , such as a nonzero number, go to step 3. Otherwise, the while statement is completed and execution resumes at the next statement after the while loop. 3. Run the statement block statement(s) . 4. Go to step 1. Looping is commonly used to perform an action while a counter variable is less than a specified value. At the end of each loop, the counter is incremented until the specified value is reached. At that point, the condition is no longer true , and the loop ends. The curly braces ( {} ) used to enclose the block of statements to be executed by the while statement are not necessary if only one statement will execute. Example In the following example, the while statement is used to test an expression. When the value of i is less than 20, the value of i is traced. When the condition is no longer true , the loop exits. var i:Number = 0; while (i<20) { trace(i); CHAPTER 2 ActionScript Language Reference 1006 Chapter 2: ActionScript Language Reference i += 3; } The following result is displayed in the Output panel. 0 3 6 9 12 15 18 See also do while, continue, for, for in with 1007 with Availability Flash Player 5. Usage with (object:Object) { statement(s); } Parameters object An instance of an ActionScript object or movie clip. statement(s) An action or group of actions enclosed in curly braces ({}). Returns Nothing. Description Statement; lets you specify an object (such as a movie clip) with the object parameter and evaluate expressions and actions inside that object with the statement(s) parameter. This prevents you from having to repeatedly write the object’s name or the path to the object. The object parameter becomes the context in which the properties, variables, and functions in the statement(s) parameter are read. For example, if object is my_array , and two of the properties specified are length and concat , those properties are automatically read as my_array . length and my_array.concat . In another example, if object is state.california , any actions or statements inside the with statement are called from inside the california instance. To find the value of an identifier in the statement(s) parameter, ActionScript starts at the beginning of the scope chain specified by the object and searches for the identifier at each level of the scope chain, in a specific order. The scope chain used by the with statement to resolve identifiers starts with the first item in the following list and continues to the last item: • The object specified in the object parameter in the innermost with statement. • The object specified in the object parameter in the outermost with statement. • The Activation object. (A temporary object that is automatically created when a function is called that holds the local variables called in the function.) • The movie clip that contains the currently executing script. • The Global object (built-in objects such as Math and String). To set a variable inside a with statement, you must have declared the variable outside the with statement, or you must enter the full path to the Timeline on which you want the variable to live. If you set a variable in a with statement without declaring it, the with statement will look for the value according to the scope chain. If the variable doesn’t already exist, the new value will be set on the Timeline from which the with statement was called. CHAPTER 2 ActionScript Language Reference 1008 Chapter 2: ActionScript Language Reference Instead of using with() , you can use direct paths. If you find that paths are long and cumbersome to type, you can create a local variable and store the path in the variable, which you can then reuse in your code, as shown in the following ActionScript: var shortcut = this._parent._parent.name_txt; shortcut.text = "Hank"; shortcut.autoSize = true; For more information on best practices in writing code and code readability, see Chapter 3, “Avoiding the with statement,” on page 87 of Using ActionScript in Flash. Example The following example sets the _x and _y properties of the someOther_mc instance, and then instructs someOther_mc to go to Frame 3 and stop. with (someOther_mc) { _x = 50; _y = 100; gotoAndStop(3); } The following code snippet shows how to write the preceding code without using a with statement. someOther_mc._x = 50; someOther_mc._y = 100; someOther_mc.gotoAndStop(3); The with statement is useful for accessing multiple items in a scope chain list simultaneously. In the following example, the built-in Math object is placed at the front of the scope chain. Setting Math as a default object resolves the identifiers cos , sin , and PI to Math.cos , Math.sin , and Math.PI , respectively. The identifiers a , x , y , and r are not methods or properties of the Math object, but because they exist in the object activation scope of the function polar() , they resolve to the corresponding local variables. function polar(r:Number):Void { var a:Number, x:Number, y:Number; with (Math) { a = PI*pow(r, 2); x = r*cos(PI); y = r*sin(PI/2); } trace("area = "+a); trace("x = "+x); trace("y = "+y); } polar(3); The following result is displayed in the Output panel. area = 28.2743338823081 x = -3 y = 3 See also tellTarget XML class 1009 XML class Availability Flash Player 5 (became a native object in Flash Player 6, which improved performance significantly). Description Use the methods and properties of the XML class to load, parse, send, build, and manipulate XML document trees. You must use the constructor new XML() to create an XML object before calling any method of the XML class. An XML document is represented in Flash by the XML class. Each element of the hierarchical document is represented by an XMLNode object. Note: The XML and XMLNode objects are modeled after the W3C DOM Level 1 recommendation: www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html. That recommendation specifies a Node interface and a Document interface. The Document interface inherits from the Node interface, and adds methods such as createElement() and createTextNode() . In ActionScript, the XML and XMLNode objects are designed to divide functionality along similar lines. Method summary for the XML class Method Description XML.addRequestHeader() Adds or changes HTTP headers for POST operations. XML.appendChild() Appends a node to the end of the specified object’s child list. XML.cloneNode() Clones the specified node and, optionally, recursively clones all children. XML.createElement() Creates a new XML element. XML.createTextNode() Creates a new XML text node. XML.getBytesLoaded() Returns the number of bytes loaded for the specified XML document. XML.getBytesTotal() Returns the size of the XML document, in bytes. XML.hasChildNodes() Returns true if the specified node has child nodes; otherwise, returns false . XML.insertBefore() Inserts a node in front of an existing node in the specified node’s child list. XML.load() Loads a document (specified by the XML object) from a URL. XML.parseXML() Parses an XML document into the specified XML object tree. XML.removeNode() Removes the specified node from its parent. XML.send() Sends the specified XML object to a URL. XML.sendAndLoad() Sends the specified XML object to a URL, and loads the server response into another XML object. XML.toString() Converts the specified node and any children to XML text. CHAPTER 2 ActionScript Language Reference 1010 Chapter 2: ActionScript Language Reference Property summary for the XML class Collections summary for the XML class Event handler summary for the XML class Property Description XML.contentType The MIME type transmitted to the server. XML.docTypeDecl Sets and returns information about an XML document’s DOCTYPE declaration. XML.firstChild Read-only; references the first child in the list for the specified node. XML.ignoreWhite When set to true , discards, during the parsing process, text nodes that contain only white space. XML.lastChild Read-only; references the last child in the list for the specified node. XML.loaded Read-only; checks whether the specified XML object has loaded. XML.nextSibling Read-only; references the next sibling in the parent node’s child list. XML.nodeName The node name of an XML object. XML.nodeType The type of the specified node (XML element or text node). XML.nodeValue The text of the specified node if the node is a text node. XML.parentNode Read-only; references the parent node of the specified node. XML.previousSibling Read-only; references the previous sibling in the parent node’s child list. XML.status A numeric status code that indicates the success or failure of an XML document parsing operation. XML.xmlDecl Specifies information about a document’s XML declaration. Method Description XML.attributes Returns an associative array that contains all the attributes of the specified node. XML.childNodes Read-only; returns an array that contains references to the child nodes of the specified node. Event handler Description XML.onData Invoked when XML text has been completely downloaded from the server, or when an error occurs downloading XML text from a server. XML.onLoad Returns a Boolean value indicating whether the XML object was successfully loaded with XML.load() or XML.sendAndLoad() . [...]... The following example is from the XML_languagePicker FLA file in the Examples directory and can be found in the languageXML.onLoad event handler function definition: // loop through the strings in each language node // adding each string as a new element in the language array 1024 Chapter 2: ActionScript Language Reference for (var stringNode:XMLNode = childNode.firstChild;... */ The XML_blogTracker.fla and XML_languagePicker.fla files in the HelpExamples folder also contain a code example The following are typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • 1030 Chapter 2: ActionScript Language Reference XML.insertBefore() Availability... array and use the child nodes to populate it var secondArray:Array = rootNode.childNodes; trace(secondArray); // output: ,, See also XML.nodeType 1016 Chapter 2: ActionScript Language Reference XML.cloneNode() Availability Flash Player 5 Usage my_xml.cloneNode(deep:Boolean) : XMLNode Parameters A Boolean value; if set to true, the children of the specified XML object... added): // // // // // // // // // // // // 1018 Chapter 2: ActionScript Language Reference to rootNode XML.contentType Availability Flash Player 6 Usage my_xml.contentType:String Description Property; the MIME content type that is sent to the server when you call the... doc.appendChild(element1); element1.appendChild(element2); element1.appendChild(element3); trace(doc); // output: See also XML.createTextNode() 1020 Chapter 2: ActionScript Language Reference XML.createTextNode() Availability Flash Player 5 Usage my_xml.createTextNode(text:String) : XMLNode Parameters text A string; the text used to create the new text node Returns... breaks added between tags): // // textNode1 // textNode2 // XML.createTextNode() 1021 See also XML.createElement() 1022 Chapter 2: ActionScript Language Reference XML.docTypeDecl Availability Flash Player 5 Usage my_xml.docTypeDecl:String Description Property; specifies information about the XML document’s DOCTYPE declaration After the... addRequestHeader() method var headers:Array = new Array("Content-Type", "text/plain", "X-ClientAppVersion", "2.0"); my_xml.addRequestHeader(headers); See also LoadVars.addRequestHeader() 1012 Chapter 2: ActionScript Language Reference XML.appendChild() Availability Flash Player 5 Usage my_xml.appendChild(childNode:XMLNode) : Void Parameters An XMLNode that represents the node to be moved from its current location... trace("intervalID: " + intervalID); } doc.load("[place a valid URL pointing to an XML file here]"); var intervalID:Number = setInterval(checkProgress, 100, doc); See also XML.getBytesTotal() 1026 Chapter 2: ActionScript Language Reference XML.getBytesTotal() Availability Flash Player 6 Usage my_xml.getBytesTotal() : Number Parameters None Returns An integer Description Method; returns the size, in bytes, of the... { if (aNode.nodeType == 1) { trace(aNode.nodeName+":\t"+aNode.firstChild.nodeValue); } } } The following is displayed in the Output panel: output: username:hank password:rudolph 1028 Chapter 2: ActionScript Language Reference XML.ignoreWhite Availability Flash Player 5 Usage my_xml.ignoreWhite:boolean XML.prototype.ignoreWhite:boolean Parameters boolean A Boolean (true or false) value Description Property;... root node (named clone) of doc1 var newNode:XMLNode = doc1.createElement("newbie"); clone.appendChild(newNode); trace ("doc1: " + doc1); // output: doc1: 1014 Chapter 2: ActionScript Language Reference XML.attributes Availability Flash Player 5 Usage my_xml.attributes:Array Description Property; an associative array that contains all the attributes of the specified XML object . i:Number = 0; while (i<20) { trace(i); CHAPTER 2 ActionScript Language Reference 1006 Chapter 2: ActionScript Language Reference i += 3; } The following result. which the with statement was called. CHAPTER 2 ActionScript Language Reference 1008 Chapter 2: ActionScript Language Reference Instead of using with() ,

Ngày đăng: 24/12/2013, 01:17