MovieClip Object Prototype explanation

Source: Internet
Author: User
Object expands the new method under the MovieClip object, and all the movie clips below it benefit automatically.

Expansion of the image method:

ActionScript does not have the syntax to flip a movie clip horizontally, now using a prototype to expand a method,

Movieclip.prototype.flipx=function () {

This._xscale=-this._xcale;

}

Any movie clip can use this method to flip horizontally.

Syntax: Movie clips. flipx ();

Control all the right image

When making a game, there are times when you want all of the movie clips to stop playing, and you can't use the For loop command to do so. If a movie clip is created dynamically, you should not use the above method.

All movie clips belong to the MovieClip object, using prototypes to create powerful ways to control all movie clips.

You can control all movie clips by using a For loop that accesses all of the movie clips underneath the MovieClip object.

MovieClip.prototype.stopall () =function () {

for (var I and this) {

This[i].stop ();

}

}

StopAll () is a custom method, this. refers to the MovieClip object, which, like an array, records all movie clips, using this[i] to control each movie clip.

2 Expansion of static objects:

Some objects cannot use the new syntax to create an instance, which is called a static object, and they cannot use the prototype extension method.

Static object has key Math Mouse Selection;

To expand a method for the Math object,

Math.distanse=function (x1,x2,y1,y2) {

var distx=x2-x1;

var disty=y2-y1;

Return Math.sqrt (DISTX*DISTX+DISTY*DISXY)

}

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.