Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*+----------+----------+----------+----------+
- @neirao
- for Sprites Sheets multiresolution devices!
- [loop for movieclips in library and resize your all frames]
- +----------+----------+----------+----------+
- updates:
- +----------+----------+----------+----------+
- -
- -
- -17/09/2017
- +----------+----------+----------+----------+
- missing:
- +----------+----------+----------+----------+
- - select the position, top left, center etc.. in menu
- - jump not keyframes... same imagens on mcs frames
- +----------+----------+----------+----------+*/
- fl.outputPanel.clear();
- fl.trace("initialize...");
- trace_line = "+----------+----------+----------+----------+";
- fl.trace(trace_line);
- //fl.trace("timeline: " + timeline + " - totalframes: " + frames); //timeline: [object Timeline] - totalframes: 1
- var doc = fl.getDocumentDOM();
- if (doc == null || doc.getTimeline() == null) {
- alert("Please open or create a .fla file!");
- } else {
- var lib = doc.library;
- var sel = doc.selection;
- var timeline = doc.getTimeline();
- var frames = timeline.frameCount;
- //+----------+----------+----------+----------+
- //@2
- var resize_stage = true; //se vai ou não redimeziona o stage e posicionar os elementos no palco!!
- var mcs_on_stage = 0; //conta se tem ou não MovieClip elementos no palco!
- var mcs_on_library = 0; //conta se tem ou não MovieClip elementos na library!
- //+----------+----------+----------+----------+
- var percent=null;
- //+----------+----------+----------+----------+
- enterPercent();
- //resizeMovieClipsOnStage();
- }
- function enterPercent(){
- //@2
- //+----------+----------+----------+----------+
- var ret = prompt("Enter a percent number, (like 0.5 || 2.0):");
- //var percent = prompt("percent(like 0.5 || 2.0 etc... ):", '');//direto
- if (ret != null) {
- //var percent = parseFloat(ret);
- percent = parseFloat(ret);//para ser global
- if (isNaN(percent)) {
- alert("the percent no is a Number valid... try again...");
- return;
- }
- } else {
- alert("type some value... try again...");
- return;
- }
- //all ok, continue
- //if (ret != null && !isNaN(percent)) {
- resizeMovieClipsOnStage();
- //}
- }
- function resizeMovieClipsOnStage() {
- fl.trace("resizeMovieClips...on stage..");
- fl.trace(trace_line);
- //[loop layers]
- fl.trace("timeline.layers.length: " + timeline.layers.length); //2
- fl.trace("timeline.layerCount: " + timeline.layerCount); //2
- fl.trace(trace_line);
- //+----------+----------+----------+----------+
- for (var i = 0; i < timeline.layers.length; i++) {
- var layer = timeline.layers[i];
- fl.trace(layer.name + " - " + layer.layerType);
- //fl.trace("layer: "+layer);//layer: [object Layer]
- //fl.trace("layer.frames.length: "+layer.frames.length);//layer.frames.length: 1
- /*
- layer.layerType: mask
- layer.layerType: guide
- layer.layerType: normal
- layer.layerType: normal */
- if (layer.layerType == "normal") {
- //[loop frames]
- for (var j = 0; j < layer.frames.length; j++) {
- var frame = layer.frames[j];
- //fl.trace("frame: "+frame);//[object Frame]
- //[loop elements]
- for (var k = 0; k < frame.elements.length; k++) {
- var element = frame.elements[k];
- fl.trace("element: " + element + " - elementType: " + element.elementType);
- fl.trace(trace_line);
- /*
- element: [object SymbolInstance] - elementType: instance = [MovieClip / Button / Graphic] <<<
- element: [object Shape] - elementType: shape
- element: [object Text] - elementType: text */
- //if is [MovieClip / Button / Graphic] //=="button"
- if (element.elementType == "instance") {
- if (element.libraryItem.itemType == "movie clip") {
- //@2 conta se tem elementos no palco!
- mcs_on_stage++;
- var item_lib_name = element.libraryItem.name;
- fl.trace("item_lib_name: " + item_lib_name);
- //# [MISSING]
- //CRIAR AQUI para reduzir somente se tiver keyframe "."
- //#
- fl.trace("indexOf: " + item_lib_name.indexOf("Export/")); //0 ou -1
- if (item_lib_name.indexOf("Export/") != -1) {
- fl.trace("o item '" + item_lib_name + "' está na pasta EXPORT!!!");
- } else {
- fl.trace("o item '" + item_lib_name + "' NÃO está na pasta EXPORT!!!");
- }
- /*
- //+----------+----------+----------+----------+
- //temp OK
- /*lib.selectAll(true);//ok
- var selectedItems = lib.getSelectedItems().slice();
- fl.trace("selectedItems: " + selectedItems);//[object SymbolItem],[object SymbolItem],[object SymbolItem],[object SymbolItem]
- fl.trace("selectedItems.length: "+selectedItems.length);//selectedItems.length: 4*/
- //+----------+----------+----------+----------+
- //lib.selectItem(item_lib_name);//ok seleciona 1 por 1
- fl.trace("element.libraryItem: " + element.libraryItem); //element.libraryItem: [object SymbolItem]
- //lib.editItem(item_lib_name);
- //doc.selectAll();
- //+----------+----------+----------+----------+
- //do timeline_reader.jsfl...
- var frames_in_element = element.libraryItem.timeline.frameCount;
- for (x = 0; x < frames_in_element; x++) {
- fl.trace("x: " + x);
- element.libraryItem.timeline.currentFrame = x;
- //# [MISSING]
- //CRIAR AQUI para reduzir somente se tiver keyframe "."
- //#
- lib.editItem(item_lib_name);
- doc.selectAll();
- //doc.scaleSelection(0.50, 0.50, "top left");//ok direto
- //@2
- doc.scaleSelection(percent, percent, "top left");
- //doc.transformSelection(100,100,100,100);//zica
- }
- //fl.trace("item_lib_name: " + item_lib_name + " - frames: " + frames);
- doc.exitEditMode();
- //@2 OKKKKKKKKKKK
- //tem que ser APOS FECHAR O EDIT MODE!! OKKK
- //fl.trace("element.x ("+item_lib_name+")"+element.x);
- //fl.trace("element.y ("+item_lib_name+")"+element.y);
- if (resize_stage) {
- element.x *= percent;
- element.y *= percent;
- //centraliza o point!!
- //MISSING..ERRO..
- var px=(element.x-element.width)*percent;//element.x;//-(element.width/2);
- var py=(element.y-element.height)*percent;//element.y;//-(element.height/2);
- doc.setTransformationPoint({x:px, y:py});
- }
- }
- }
- }
- }
- }
- }
- doc.exitEditMode();
- fl.trace(trace_line);
- fl.trace("movieclips no stage: " + mcs_on_stage);
- if (mcs_on_stage > 0) {
- fl.trace(trace_line);
- if (resize_stage) {
- doc.width = doc.width * percent;
- doc.height = doc.height * percent;
- }
- fl.trace("movieclips and stage resized * " + percent * 100 + "%");
- fl.trace(trace_line);
- fl.trace("the end...STAGE MODE");
- }
- if (mcs_on_stage <= 0) {
- fl.trace("no theres movieclips on stage!!\n We will try in Library 'Export folder...'");
- resizeMovieClipsOnLibrary();
- }
- }
- //# [MISSING]
- //CRIAR AQUI para reduzir somente se tiver keyframe "."
- //#
- function resizeMovieClipsOnLibrary() {
- fl.trace(trace_line);
- fl.trace(trace_line);
- fl.trace("search Movieclips ...on Library... only on [Export/]folder!");
- fl.trace("selectLibraryItems");
- fl.trace(trace_line);
- fl.trace(trace_line);
- lib.selectAll(); //okk
- //lib.selectItem("Export");//ok só folder
- items = lib.getSelectedItems();
- fl.trace(items.length + " items selecionados na library: " + items);
- if (items.length <= 0) {
- alert("Sem itens para selecionar na Library!!");
- return;
- } else {
- for (var i = 0; i < items.length; i++) {
- var element = items[i]
- fl.trace("element: " + element);
- fl.trace("element.itemType: " + element.itemType);
- fl.trace(trace_line);
- //no stage movieclip.. "element.libraryItem.name"
- //if (element.libraryItem.itemType == "movie clip") {
- if (element.itemType == "movie clip") {
- //
- var item_lib_name = element.name;
- fl.trace("item_lib_name: " + item_lib_name);
- //# [MISSING]
- //CRIAR AQUI para reduzir somente se tiver keyframe "."
- //#
- //fl.trace("indexOf: " + item_lib_name.indexOf("Export/")); //0 ou -1
- //fl.trace("element.libraryItem: " + element.libraryItem); //aqui erro(element.libraryItem: undefined) element.libraryItem: [object SymbolItem]
- //aqui é..
- fl.trace("element.libraryItem: " + element); //ok element.libraryItem: [object SymbolItem]
- if (item_lib_name.indexOf("Export/") != -1) {
- fl.trace("o item '" + item_lib_name + "' está na pasta EXPORT!!!");
- mcs_on_library++;
- //var frames_in_element = element.libraryItem.timeline.frameCount;
- var frames_in_element = element.timeline.frameCount;
- for (x = 0; x < frames_in_element; x++) {
- fl.trace("x: " + x);
- element.timeline.currentFrame = x;
- //# [MISSING]
- //CRIAR AQUI para reduzir somente se tiver keyframe "."
- //#
- lib.editItem(item_lib_name);
- doc.selectAll();
- //doc.scaleSelection(0.50, 0.50, "top left");//ok direto
- //@2
- doc.scaleSelection(percent, percent, "top left");
- }
- //fl.trace("item_lib_name: " + item_lib_name + " - frames: " + frames);
- doc.exitEditMode();
- //aqui não usa o .X E .Y!! só no Stage!!
- } else {
- fl.trace("o item '" + item_lib_name + "' NÃO está na pasta EXPORT!!!");
- }
- }
- }
- }
- doc.exitEditMode();
- fl.trace(trace_line);
- fl.trace("Total movieclips no library: " + mcs_on_library);
- if (mcs_on_library > 0) {
- fl.trace(trace_line);
- if (resize_stage) {
- doc.width = doc.width * percent;
- doc.height = doc.height * percent;
- }
- fl.trace("movieclips and stage resized * " + percent * 100 + "%");
- }
- if (mcs_on_library <= 0) {
- fl.trace("no theres movieclips on stage!!\n We will try in Library 'Export folder...'");
- alert("NO THERES MOVIECLIPs on stage or in library!! Please create!!");
- return;
- }
- fl.trace(trace_line);
- fl.trace("the end...LIBRARY MODE!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement