Java code
// Open the image directory
Var folder = fl. browseForFolderURL ("png Image directory ");
// Obtain the file list handle
Var list = FLfile. listFolder (folder, "files ");
Var doc = null;
If (list ){
// Loop this handle to get all the sub-Files
For (var I = 0; I <list. length; I ++ ){
Var filename = list [I];
If (filename. toLowerCase (). substr (filename. length-4) = ". png "){
If (doc = null ){
// Create a fla. The default value is timeline.
Doc = fl. createDocument ();
Doc. frameRate = 30;
Doc. width = 100;
Doc. height = 100;
Doc. backgroundColor = '#000000 ';
}
// Import the file to the flash/stage/Library
Doc. importFile (folder + "/" + filename, true );
}
}
}
If (doc ){
// Library read-only attribute, database panel
Var lib = doc. library;
// Add a movie clip name to the library named npc
Lib. addNewItem ("movie clip", "npc ");
// Edit this mc
Lib. editItem ("npc ");
// Obtain the current timeline object. The current timeline can be the current scenario, the current component being edited, or the current screen.
Var tl = doc. getTimeline ();
// Set the layer to selected, and specify the layer as the current layer.
Tl. setSelectedLayers (0 );
// Read-only; layer object array name
Tl. layers [0]. name = "bitmap ";
// Calculate how many images are inserted to a specified number of frames at the specified frame number.
Var len = lib. items. length-1;
Tl. insertFrames (len-1 );
// Set the first shot and write the image
Var frameId = 0;
// All items in the lib. items project library
For (var I = 0; I <lib. items. length; I ++ ){
Var item = lib. items [I];
If (item. itemType = "bitmap "){
// A Boolean value that specifies whether the bitmap can be smoothly processed
Item. allowSmoothing = true;
// A string that determines the compression type applied to bitmap
Item. compressionType = "photo ";
// An integer used to specify the bitmap Quality
Item. quality = 70;
If (frameId> 0 ){
// Converttoblkkeyframes method; converts frames of the current layer to blank key frames.
Tl. converttoblkkeyframes (frameId );
}
// AddItemToDocument method; Add the current project or specified project to the specified position of the stage
Lib. addItemToDocument ({x: 0, y: 0}, item. name );
// Push the needle forward
FrameId ++;
}
}
// Add a new layer
// Tl. addNewLayer ();
// Name the action Layer
// Tl. layers [0]. name = "actions ";
// Add the first and last actions
// Tl. setSelectedFrames ([0, len-1, len-1], true );
// Tl. converttoblkkeyframes (1 );
// Tl. layers [0]. frames [0]. actionScript =
// "If (this ['cyc'] = null) {\ nthis ['cyc'] = false; \ nstop (); \ n} \ nif (! This ['cyc']) {\ nstop (); \ n }";
// Find the mc and add the class path link to it.
// Var li = lib. items [lib. findItemIndex ("npc")];
// Li. linkageExportForAS = true;
// Li. linkageExportInFirstFrame = true;
// Li. linkageClassName = "npc ";
// Export swf
Var li = lib. items [lib. findItemIndex ("npc")];
Alert (li );
Doc. addItem ({x: 0, y: 0}, li );
// Doc. exportSWF ();
// Close this file
// Doc. close (false );
} Else {
Alert ("no specified png image! ");
}