cmxcmz2002
07-30-2004, 03:17 PM
I have a JSFL file I wrote that recursively runs through all the layers,frames, and elements, to pick up all the instance name and text name and change them to lowercased names.
I do this because I have tons of code in Actionscript1.0 and I need to solve the case-sensitivity problem in order to update them to Flash 7. So instead of going through by hand I thought I could batch them with a JSFL script.
I use a recursive function to pick up all the instance. In order to get all the elements inside of an object, I need to change the document.selection to select an object and enter its edit mode.( It will be greatly appreciated if anyone can give another solution without using "enterEditMode")
Here is the problem. When I change the document.selection and execute document.enterEditMode, an alert msg appears: "enterEditMode:no selection ". I am pretty sure I have already assign an element to the "document.selection".
Any suggestion welcomed.
Code:
function searchAndReplace(currElement)
{
// if no instance in the current frame, then exitEditMode
//var exitEditFlag = true;
fl.trace("Start to search and replace in the symbol/document: " + currElement)
//assigns the layers array to the variable "theLayers"
var theLayers = fl.getDocumentDOM().getTimeline().layers;
//creates an array to hold all the elements that are instances of "myMovieClip"
//counter variable
// var x = 0;
//begin loop through all the layers
for(i = 0 ; i < theLayers.length; i++)
{
var theFrames = theLayers [i ].frames;
//begin loop through all the frames in a layer
for(j = 0 ; j < theFrames.length; j++)
{
var k = 0;
var theElems = theLayers [i ].frames [j ].elements;
//begin loop through all the elements in a frame
for(k = 0 ; k < theElems.length; k++)
{
var theElemType = theElems [k ].elementType;
if( theElemType == "instance") //if the element is of type "instance"
{
// if a instance exists in the current frame, then call the recursive function
//exitEditFlag = false;
// change the instance name
var tmpStr = theElems [k].name;
if(tmpStr != "" && tmpStr != null)
{
theElems [k].name = tmpStr.toLowerCase();
fl.trace(tmpStr + "==>" + theElems [k ].name);
}
// enter the editting mode of the current element
var currSelectionArray = new Array;
currSelectionArray [0] = theElems [k];
fl.getDocumentDOM().selection = currSelectionArray;
var hasSelected = fl.getDocumentDOM().selection;
//if(hasSelected != 0 )
//{
fl.getDocumentDOM().enterEditMode("inPlace");
// recursive function is called
searchAndReplace(theElems[k ].name);
//}
//else
//alert(theElems[k ].name + " hasSelected = 0");
} //
else if( theElemType == "text") // if it is a text
{
var tmpStr = theElems [k ].name;
if(tmpStr != "" && tmpStr != null)
{
theElems [k].name = tmpStr.toLowerCase();
fl.trace(tmpStr + "==>" + theElems [k ].name);
}
}
}
}
}
fl.getDocumentDOM().exitEditMode(); // Now the loop reaches the ending condition
};
// main code
var currElement = fl.getDocumentDOM().name;
var count =0;
searchAndReplace(currElement);
I do this because I have tons of code in Actionscript1.0 and I need to solve the case-sensitivity problem in order to update them to Flash 7. So instead of going through by hand I thought I could batch them with a JSFL script.
I use a recursive function to pick up all the instance. In order to get all the elements inside of an object, I need to change the document.selection to select an object and enter its edit mode.( It will be greatly appreciated if anyone can give another solution without using "enterEditMode")
Here is the problem. When I change the document.selection and execute document.enterEditMode, an alert msg appears: "enterEditMode:no selection ". I am pretty sure I have already assign an element to the "document.selection".
Any suggestion welcomed.
Code:
function searchAndReplace(currElement)
{
// if no instance in the current frame, then exitEditMode
//var exitEditFlag = true;
fl.trace("Start to search and replace in the symbol/document: " + currElement)
//assigns the layers array to the variable "theLayers"
var theLayers = fl.getDocumentDOM().getTimeline().layers;
//creates an array to hold all the elements that are instances of "myMovieClip"
//counter variable
// var x = 0;
//begin loop through all the layers
for(i = 0 ; i < theLayers.length; i++)
{
var theFrames = theLayers [i ].frames;
//begin loop through all the frames in a layer
for(j = 0 ; j < theFrames.length; j++)
{
var k = 0;
var theElems = theLayers [i ].frames [j ].elements;
//begin loop through all the elements in a frame
for(k = 0 ; k < theElems.length; k++)
{
var theElemType = theElems [k ].elementType;
if( theElemType == "instance") //if the element is of type "instance"
{
// if a instance exists in the current frame, then call the recursive function
//exitEditFlag = false;
// change the instance name
var tmpStr = theElems [k].name;
if(tmpStr != "" && tmpStr != null)
{
theElems [k].name = tmpStr.toLowerCase();
fl.trace(tmpStr + "==>" + theElems [k ].name);
}
// enter the editting mode of the current element
var currSelectionArray = new Array;
currSelectionArray [0] = theElems [k];
fl.getDocumentDOM().selection = currSelectionArray;
var hasSelected = fl.getDocumentDOM().selection;
//if(hasSelected != 0 )
//{
fl.getDocumentDOM().enterEditMode("inPlace");
// recursive function is called
searchAndReplace(theElems[k ].name);
//}
//else
//alert(theElems[k ].name + " hasSelected = 0");
} //
else if( theElemType == "text") // if it is a text
{
var tmpStr = theElems [k ].name;
if(tmpStr != "" && tmpStr != null)
{
theElems [k].name = tmpStr.toLowerCase();
fl.trace(tmpStr + "==>" + theElems [k ].name);
}
}
}
}
}
fl.getDocumentDOM().exitEditMode(); // Now the loop reaches the ending condition
};
// main code
var currElement = fl.getDocumentDOM().name;
var count =0;
searchAndReplace(currElement);