The same-sex and difference _javascript skills of JavaScript and ACTIONSCRIPT3

Source: Internet
Author: User

What are the criteria for JavaScript and ActionScript, you know?

ActionScript and JavaScript share a common standard: ECMAScript. Therefore, if you have ever written a condition (an "if statement") or an iteration ("loop statement") with JavaScript, you can use ActionScript. Remember that JavaScript is case-sensitive, as is the case with ActionScript.

Let's take a look at the same sex and diversity:

Common:

A), the two grammars similar, all follow the ECMAScript standard (click to view ECMAScript5.1 Chinese version);

b), can be run on the client, is the construction of RIA application of the more popular programming language;

Difference:

A), the operation of the two different display: JavaScript operation DOM Object, ActionScript3.0 operation is displayobject;

b, the operating environment is different: JavaScript needs JavaScript engine parsing, execution, ActionScript3 need Adobe Flash Player (AVM2) to parse;

c), ActionScript3.0 introduces OOP concepts, can use extends to implement inheritance, and JavaScript can only be implemented on a prototype basis;

d), the application of the field is different: JavaScript is currently mainly used in Web pages (PC end, mobile terminals, etc.), and ActionScript3.0 in the Web game application is more;

Digression (personal ideas for reference only): In terms of remuneration alone, AS3 floating than JS to large, if you participate in the development of a page game recharge water more than 5 million (to the major page of the platform to look at open service, single monthly recharge by 5~10w to calculate, if open to 100 groups, advertising cost page tour probably in 2~ 15 yuan/registrant), the general bonus is also relatively considerable (the project's main front and back may be more, the distribution of the proportion of the companies must have their own agreement). But most of the "entrepreneurial" small companies to develop web games, it is difficult to grow, close the majority, which means higher risk. And the front end, the big company's door is always open for you (pay is also good). I hope that before the age of 30, have the opportunity to write a hands-on experience to participate in the "entrepreneurial" experiences, from JS front-end to the process of AS3 front-end, but also to give their 30 birthday a gift:

About entrepreneurship, transfer, management, have the opportunity to write their own ideas, now not too mature, pull far, or simply back to the technology. Since it is those things, then JavaScript and ACTIONSCRIPT3 must have some intersection, here in a browser-based scenario to summarize:

1, AS3 get the parameters of the Web page passed over;

2, JS and AS3 Mutual call;

Starting with "rendering SwF", first use JS to determine if the current browser has Flash Player installed, then get its version, meet the minimum Flash Player version, and then dynamically create the DOM node and append it to the page. Click to view the JavaScript detect Flash Player version number

Rendering SWF, general use of swfobject.js (note swfobject.js version, ver1.5 and ver2.0+ usage is significantly different), related documents here >>

There are two ways the page passes to the SWF parameter:

1, the Path parameter: <param name= "movie" Value= "Xxx.swf?v ..."/> <embed src= "xxx.swf?v ..."/>

2, the use of Flashvars:<param name= ' "Flashvars" value= "..."/> <embed src= "xxx.swf" flashvars= "..."/>

AS3 Get Parameters Root.loaderInfo.parameters or Stage.loaderInfo.parameters

Flex-generated SWF can be directly obtained via Application.application.parameters

If you are using AS3 's shell to load the SWF generated by Flex, assume that the following code is defined in AS3 's "shell":

public var param_obj:object;
Param_obj = this.loaderInfo.parameters;

So the way that flex generates a SWF gets a parameter:

var system_obj:object = Object (Systemmanager (Systemmanager.getswfroot (This)). Gettoplevelroot ());
var obj:object = system_obj.param_obj;

Sample code (AS3):

Package {import flash.display.Sprite; import flash.events.Event; import flash.external.ExternalInterface;/** * ... * @au Thor Meteoric_cry */public class Main extends Sprite {public Function main (): void {if (stage) init (); Else addeventlist Ener (Event.added_to_stage, init);  Private Function init (e:event = null): void {RemoveEventListener (event.added_to_stage, init);//Entry point Initview (); Private Function Initview (): void {var obj:object = this.loaderInfo.parameters; var kk:string = obj[' KK ']; if (External interface.available) {externalinterface.call (' alert ', KK);} } }

HTML code:

 <! DOCTYPE html> 
 

The above argument "allowScriptAccess" has a value of three: Always, Samedomain, never

The default value is: Samedomain, that is, allow SWF calls to the same domain as the JS function, if set to never is not allowed to call, and always without any restrictions, SWF can be called directly.

If you change the value of the previous page's parameter allowscriptaccess to "Samedomain", you will receive the following:

If the page needs to load a remote SWF file, if you need the SWF to make the call to JS, you need to add in the code:

Security.allowdomain ("*"); 
Security.allowinsecuredomain ("*");

After the registration: Externalinterface.addcallback (' Jscallback ', jscallback); Otherwise the call will fail (no exception will be thrown)

AS3 the method used to call JS: Externalinterface.call

And JS call AS3 need to "register" in AS3, and must wait for the SWF to load, after registration, to call its method

AS3 registration: Externalinterface.addcallback (' FnName ', fnname);

One of the fnname for SWF external "open" interface, and JS Direct use (document[' swfname ') | | | | | window[' swfname ']). FnName (); Call can, and call the JS function, you need to pass arguments directly in the function call () "The appropriate parameters can be added."

IE can be viewed through the node tool to view the SWF "exposed" method, other browsers can not directly view

I have also written about as and JS related articles before:

Flash in the Web application of a number of special application scenarios >>

Chrome, FF Flash MouseWheel event failure (wmode=transparent) >>

JS and as mutual invocation, a more typical application: cross-browser music player (list using JS rendering, swf external "public" play, pause, stop, etc.)

The above is a small set of JavaScript and ACTIONSCRIPT3 to introduce both the same sex and differences, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.