Copy link to clipboard
Copied
This feature is not available when using the old version of an,It can only be solved with this command,but having trouble with the code
var symbolName = prompt("Enter new graphic name");
if(symbolName != null) {
var version = fl.version;
var versionNum = parseInt(version.substring(version.indexOf(" "), version.indexOf(",")));
var dom = fl.getDocumentDOM();
var tl = dom.getTimeline();
//create rectangle at top (guide for stage)
var guideLayerNum = tl.addNewLayer('_stageGuide');
tl.setSelectedLayers(guideLayerNum, true);
var stroke = dom.getCustomStroke('toolbar');
var strokeCopy = dom.getCustomStroke('toolbar');
var fill = dom.getCustomFill('toolbar');
var useCustomStroke = new Boolean();
useCustomStroke = stroke.style == "noStroke" && fill.style == "noFill";
if(useCustomStroke) {
//fillCopy.color = 0xffffff; //attempting to set this var crashes flash
stroke.style = 'solid';
stroke.thickness = 1;
stroke.color = 0xff0000; //deprecated as of CS3
//stroke.shapeFill.color = 0xff0000; //(for next version of Flash)
if(versionNum >= 8) stroke.scaleType ='none'; //flash 8 & above
dom.setCustomStroke(stroke);
}
var w = parseInt(dom.width);
var h = parseInt(dom.height);
dom.addNewRectangle({left:0,top:0,right:w,bottom:h},0, false, false);
tl.setLayerProperty('locked', true);
tl.reorderLayer(guideLayerNum, 0, true);
var frameSeq = tl.getSelectedFrames();
var layerSeq = tl.getSelectedLayers();
var lib = dom.library;
//clear [user] selected layers
var selLayers = tl.getSelectedLayers();
for(var i = 0; i < selLayers.length; i++){
tl.setSelectedLayers(selLayers[i], true);
}
//clear [user] selected frames
var clearFrameSel = new Array();
for (var i = 0; i < frameSeq.length; i+=3){
var tlayer = frameSeq[i];
clearFrameSel.push(tlayer, -1, -1);
tl.currentLayer = tlayer;
tl.setSelectedLayers(tlayer, true);
}
tl.setSelectedFrames(clearFrameSel, true);
var layerProps = new Array();
//select all frames in timeline
var endFrameArr = new Array();
var frameSel = new Array();
tl.expandFolder(true, true, -1); //expands all folders
for (var i = 0; i < tl.layerCount; i++){
var tlayer = tl.layers[i];
var props = new Object();
props.locked = tlayer.locked;
props.visible = tlayer.visible;
layerProps.push(props);
frameSel.push(i, 0, tl.frameCount);
endFrameArr.push(tlayer.frameCount);
tl.currentLayer = tlayer;
tl.setSelectedLayers(i, i==0);
}
tl.setSelectedFrames(frameSel, true);
tl.copyFrames();
//delete guide rectangle
//tl.deleteLayer(0);
if(symbolName == symbolName == "" || symbolName == undefined || symbolName.length < 1) symbolName = "_stageClip";
lib.addNewItem('graphic', symbolName, 'top left');
//dom.enterEditMode();
lib.editItem(symbolName);
var newTL = dom.getTimeline();
newTL.selectAllFrames();
newTL.pasteFrames();
//add end frames & set layer props
for (var i = 0; i < newTL.layerCount; i++){
if(endFrameArr[i] < newTL.frameCount){
newTL.setSelectedLayers(i, true);
newTL.removeFrames(endFrameArr[i], newTL.frameCount);
}
newTL.layers[i].locked = layerProps[i].locked;
newTL.layers[i].visible = layerProps[i].visible;
}
//set guide rectangle to outlines
newTL.setSelectedLayers(0, true);
newTL.setLayerProperty('outline', true);
newTL.setLayerProperty('layerType', 'guide');
//reset stroke color
//if(useCustomStroke) {
/*fl.trace('attempting to reset stroke');
strokeCopy.style = "noStroke";
strokeCopy.color = null;
dom.setCustomStroke(strokeCopy);*/ //won't reset to null for some reason
//}
//return to main timeline
dom.exitEditMode();
tl = dom.getTimeline();
for(var i=tl.layerCount; i > 0; i--){
tl.currentLayer = i;
tl.deleteLayer();
}
tl.currentLayer = 0;
tl.setLayerProperty('locked', false);
tl.setLayerProperty('name', symbolName);
tl.selectAllFrames();
tl.clearKeyframes();
var newLayerNum = 0;
lib.addItemToDocument({x:0, y:0}, symbolName);
tl.insertFrames(newTL.frameCount);
tl.layers[newLayerNum].frames[0].elements[0].symbolType = "graphic";
tl.layers[newLayerNum].frames[0].elements[0].firstFrame = 0;
tl.layers[newLayerNum].frames[0].elements[0].loop = "play once";
tl.layers[newLayerNum].frames[0].elements[0].x = dom.width/2;
tl.layers[newLayerNum].frames[0].elements[0].y = dom.height/2;
}
Copy link to clipboard
Copied
You can use Timeline Block To Symbol.
Copy link to clipboard
Copied
Hope to optimize the code I provided to achieve this functionality