Use jsfl to export the elements in flash as PNG

Source: Internet
Author: User

In the past two days, jsfl has been drumming for the purpose of porting existing flash projects that show chinese character strokes to other platforms for implementation. The most recent plan was to implement these projects on the Android platform, and further implementation with HTML + Js.

1. Requirements

The current problem is: how to export the existing Chinese Character pen information without any difference, mainly the horizontal and vertical coordinates of each image and the image. The current flash stage effect is as follows:

We can see that in the early days of this stroke project, each stroke was made into a button, and each stroke was a button with different instance names. According to the different writing sequence, the name has been killed, S1, s2, s3 .... this information, coupled with the XY position of each stroke, is done manually, and it is impossible to repeat so many Chinese characters. Therefore, you must find a way to save the shape of each Chinese character stroke as an image, and save the pen Shun and position information of each stroke with the image at the same time.

2. WriteCodePrevious Thoughts

Some examples of saving library elements as PNG images are found on the internet, but if they are followed, the existing writing sequence and stroke position information will not be saved. You can directly select a component on the stage to obtain the component location, Instance name, and other information. However, jsfl cannot directly export a selected component. Therefore, we can only combine these two methods: first, select the stroke elements on the stage and name them in the Library (element. libraryitem. name) as the basis for selecting components in the library. Because the component in the library does not directly export the PNG method, you have to go back and forth: place it in a new file, ensure that only this element is available for the new file and the entire file is exported to PNG. To do this, you must first add this component to the stage library. additemtodocument, and then cut, create a document, paste into a new document and other operations, of course, you must also adjust the size of the new file according to the size of the component, tailor.

3. Upload the code

//
VaR Folderuri = fL. browseforfolderurl ("select the FLA File Location :");
VaR Filemask = "*. fla ";
VaR Foldercontents = flfile. listfolder (folderuri + "/" + filemask, "Files ");
If (Foldercontents ){
For ( VaR I = 0; I! = Foldercontents. length; ++ I ){
VaR Thisfile = folderuri + "/" + foldercontents [I];
VaR Thisfolder = folderuri + "/" + foldercontents [I]. substr (0, foldercontents [I]. lastindexof (". fla") + "/";
If (FL. opendocument (thisfile )){
If (Flfile. createfolder (thisfolder )){
// Alert (thisfolder );
VaR Doc = fL. getdocumentdom ();
Doc. selectall ();
VaR Theelems = Doc. selection;
For ( VaR C = 0; C <theelems. length; C ++ ){
If (Theelems [C]. elementtype = "instance" & theelems [C]. libraryitem. itemtype = "button "){
// Alert ("{"
// + "\" Name \ ": \" "+ theelems [C]. Name + "\","
// + "\" Libraryitem_name \ ": \" "+ theelems [C]. libraryitem. Name + "\","
// + "\" Libraryitem_itemtype \ ": \" "+ theelems [C]. libraryitem. itemtype + "\","
// + "\" Left \ ":" + theelems [C]. Left + ","
// + "\" Top \ ":" + theelems [C]. Top + ","
// + "\" Width \ ":" + theelems [C]. Width + ","
// + "\" Height \ ":" + theelems [C]. Height
// + "}");
Doc. Library. selectitem (theelems [C]. libraryitem. Name );
Doc. Library. additemtodocument ({X: 0, Y: 0 });

Doc. clipcut ();
Exportdoc = fL. createdocument ();
Exportdoc. clippaste ();
Exportdoc. selectall ();
Exportdoc. width = math. Floor (theelems [C]. width );
Exportdoc. Height = math. Floor (theelems [C]. Height );
Exportdoc. moveselectionby ({X:-exportdoc. Selection [0]. Left, Y:-exportdoc. Selection [0]. Top });

Exportdoc. selectnone ();

VaR Pngname = thisfolder + theelems [C]. Name + "_" + theelems [C]. Left + "_" + theelems [C]. Top + ". PNG ";
Exportdoc. exportpng (pngname, True , True );
Exportdoc. Close ( False );
// Alert ('saved successfully: '+ pngname );
}
}

Doc. Close ( False );
} Else {
Alert (thisfolder + "already exists. ");
}
}

}
}

4. Running Effect display

Before running: source files to be processed

After running: generate an image containing the required information

This article is from the blog in the blog Park, Article URL: Example.

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.