Copy external swf

Source: Internet
Author: User
Tags addchild

Copying external swf is a relatively advanced operation, with many steps and complicated processes. It takes a lot of time to elaborate on the principle details. Therefore, here I am lazy and I will explain it in detail. I just use code to explain the problem, and I hope to play a role in attracting others who can understand it.
Method 1 -- ByteArray deep replication

  1. Var byteLoader: URLLoader = new URLLoader ();
  2. ByteLoader. dataFormat = URLLoaderDataFormat. BINARY;
  3. ByteLoader. addEventListener (Event. COMPLETE, loadCompleteHandler );
  4. Var loader: Loader = new Loader ();
  5. Loader. y = 200;
  6. AddChild (loader );
  7. Loader. contentLoaderInfo. addEventListener (Event. INIT, loadInitHandler );
  8. Function loadInitHandler (evt: Event): void
  9. Var cloneLoder: Loader = new Loader ();
  10. AddChild (cloneLoder );
  11. CloneLoder. loadBytes (byteLoader. data );
  12. ByteLoader. load (new URLRequest ("t.swf "));
  13. Function loadCompleteHandler (evt: Event): void
  14. Loader. loadBytes (byteLoader. data );

Simple principle: use URLLoader to load external swf to ByteArray in binary data format, and then use loadBytes of the Loader class to load ByteArray in URLLoader.
Method 2 -- dynamic class replication during ApplicationDomain runtime

  1. Var loader: Loader = new Loader ();
  2. Loader. y = 200;
  3. AddChild (loader );
  4. Loader. contentLoaderInfo. addEventListener (Event. INIT, loadInitHandler );
  5. Var context: LoaderContext = new LoaderContext ();
  6. Context. applicationDomain = ApplicationDomain. currentDomain;
  7. Loader. load (new URLRequest ("t.swf"), context );
  8. Function loadInitHandler (evt: Event): void
  9. Var ClassRef: Class = loader. contentLoaderInfo. applicationDomain. getDefinition ("TestClass") as Class;
  10. Var clone_mc: MovieClip = new ClassRef ();
  11. AddChild (clone_mc );

Note:
The above two replication methods require local file-level security because they both need to load swf files;
When you use the second category (applicationdomaincategory, you must add the document class attribute to the stage when generating category t.swf. The added document class can be a specific external as class or just a name. In the above example, the document name I added is "TestClass". The parameter content in getDefinition ("TestClass") should be the same as the document class name of the swf to be copied.
ApplicationDomain has more advanced usage. If you are interested in advanced AS, you can study it.

Copy external swf

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.