将导入的属于相同序列的图片批量生成到同一元件顺序幀中并自动发布swf

/*
by wxsr 
1.将导入的属于相同序列的图片批量生成到同一元件顺序幀中
2.为调整图片的质量为无损位图类型
3.设置该元件链接属性为第一幀导出基类为MovieClip;
4.发布swf到桌面
*/
fl.getDocumentDOM().getTimeline().currentFrame = 0;
fl.getDocumentDOM().selectAll()
fl.outputPanel.clear()
fl.getDocumentDOM().distributeToLayers();
var myLayers=fl.getDocumentDOM().getTimeline().layers
fl.getDocumentDOM().selectNone();
var obj={}
for(var i=0;i<myLayers.length;i++)
{
        if(myLayers[i].frames[0].elements.length>0)
        {
                var key=myLayers[i].name.slice(0,myLayers[i].name.length-7)
                obj[key]==undefined?obj[key]=[]:'';
                obj[key].push([myLayers[i].name,i])
        }
        
}
var items=new Array()
for(var k in obj)
{
        obj[k].sort();
        var name;
        for(var v=0;v<obj[k].length;v++)
        {
                fl.getDocumentDOM().selection=myLayers[obj[k][v][1]].frames[0].elements
                name=obj[k][v][0]
                }
                fl.getDocumentDOM().convertToSymbol('movie clip',name.slice(0,name.length-7), 'bottom center');
                var lib = fl.getDocumentDOM().library;
                lib.setItemProperty('linkageExportForAS', true);
                lib.setItemProperty('linkageExportInFirstFrame', true);
                fl.getDocumentDOM().enterEditMode('inPlace');
                
                
                //alert(b);


                fl.getDocumentDOM().distributeToLayers();
                var elementLayers=fl.getDocumentDOM().getTimeline().layers
                var elements=new Array
                for(var loc_1=0;loc_1<elementLayers.length;loc_1++)
                {
                        if(elementLayers[loc_1].frames[0].elements.length==0)
                        {
                                
                                fl.getDocumentDOM().getTimeline().setSelectedLayers(0);
                                fl.getDocumentDOM().getTimeline().setSelectedFrames(0,0);
                                
                fl.actionsPanel.getScriptAssistMode();
                var b=fl.actionsPanel.setText("stop();")
                                fl.getDocumentDOM().getTimeline().insertKeyframe(1)
                                fl.getDocumentDOM().getTimeline().insertKeyframe(2)
                                fl.getDocumentDOM().getTimeline().insertKeyframe(3)
                                
                        }else {
                                elements.push([elementLayers[loc_1].name,loc_1])
                                }
                }
                elements.sort();
                var frame=0
                for(var loc_2=0;loc_2<4;loc_2++)
                {
                        if(frame<elements.length)
                        {

                                
                                
                                 fl.getDocumentDOM().getTimeline().setSelectedLayers(elements[loc_2][1]);
                                 fl.getDocumentDOM().getTimeline().setSelectedFrames(0,0);
                                 fl.getDocumentDOM().getTimeline().cutFrames(0);
                                
                        }else {
                                if(elements.length==2&&frame>1){
fl.trace(frame+'---'+elements.length)
                                        if(frame==2){
                                         fl.getDocumentDOM().getTimeline().setSelectedLayers(0);
                                         fl.getDocumentDOM().getTimeline().setSelectedFrames(0,0);
                                          fl.getDocumentDOM().getTimeline().copyFrames(0);
                                        }else if(frame==3){ 
                                         fl.getDocumentDOM().getTimeline().setSelectedLayers(0);
                                         fl.getDocumentDOM().getTimeline().setSelectedFrames(1,1);
                                         fl.getDocumentDOM().getTimeline().copyFrames(1);

                                        }
                                }
                        }
                        fl.getDocumentDOM().getTimeline().setSelectedLayers(0);
                        fl.getDocumentDOM().getTimeline().setSelectedFrames(frame,frame);
                        fl.getDocumentDOM().getTimeline().pasteFrames(frame);
                        
                        frame+=1
                }
                        var arr=fl.getDocumentDOM().getTimeline().layers
                        for(var loc_4=1;loc_4<arr.length;loc_4++)
                        {
                                        fl.getDocumentDOM().getTimeline().setSelectedLayers(1);
                                        fl.getDocumentDOM().getTimeline().deleteLayer(1);
                        }
        
                fl.getDocumentDOM().exitEditMode();

                fl.getDocumentDOM().selectNone();

        }
        for(var i_2=1;i_2<myLayers.length;i_2++)
        {
                fl.getDocumentDOM().getTimeline().setSelectedLayers(1);
                fl.getDocumentDOM().getTimeline().deleteLayer(1);
        
        }
        fl.getDocumentDOM().exportSWF("file:///C:/Documents and Settings/All Users/桌面/elementsLibs.swf");
 

你可能感兴趣的:(swf)