A fool's AS3 learning notes: Function

Source: Internet
Author: User
Tags count expression
Notes

First, the parameters of the function in AS3 can have a default value.

Public Function TestFunc () {
MyFunc ();
}
Private Function MyFunc (para1:int=10,para2:string= "str"): void{
Trace (Para1 + "," + para2); Ten, str
}

No extra parameters can be given in the AS3.

Public Function TestFunc () {
MyFunc (2, "3", 4);
}
Private Function MyFunc (para1:int,para2:string): void{
Trace (Para1 + "," + para2);
}

The compiler gave a parameter mismatch error: Argumenterror:error #1063: Argument count mismatch on Testfunc/testfunc::myfunc (). Expected 2, got 3.
So the previous method of using arguments to get the invariant parameters can not be used. AS3 gives a new keyword: ... (rest) parameter

Public Function TestFunc () {
MyFunc (2, "3", 4, "5", true);
}
Private Function MyFunc (para1:int,para2:string,... more): void{
Trace (Para1 + "," + para2); 2, 3
Trace (more); 4,5,true
}

After a fixed parameter followed by a "..." and an expression (such as "more" in the example), "..." All subsequent arguments are placed in the array named by the expression. Note "..." Must be the last parameter.

If you use the "..." arguments, you will not be able to get Arguments.callee (a reference to the currently executing function), so you can use "..." when you are certain that you are not using callee.

Referring to arguments, Arguments.caller has been "removed". To get caller, you need to pass the call function's callee as an argument to the called function. The official example:

Package {
Import Flash.display.Sprite;

public class Argumentsexample extends Sprite {
private var count:int = 1;

Public Function Argumentsexample () {
Firstfunction (TRUE);
}

Public Function Firstfunction (Callsecond:boolean) {
Trace (Count + ": firstfunction");
if (Callsecond) {
Secondfunction (Arguments.callee);
}
else {
Trace ("CALLS STOPPED");
}
}

Public Function Secondfunction (caller:function) {
Trace (Count + ": secondfunction\n");
count++;
Caller (false);
}
}
}

Small series of words: Or that sentence, we are not everyone can understand the flex so, but each of us can do a little bit of interest for our efforts. As long as your one click, a message can give the author more power. International...... Collective to fool the nest of the words of irrigation.



Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.