Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Extensions and Plugins > JSFL - Extending Flash

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-30-2004, 03:17 PM   #1
cmxcmz2002
Registered User
 
Join Date: Jul 2004
Location: Canada
Posts: 10
Question What's wrong with the "document.selection"?

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);
cmxcmz2002 is offline   Reply With Quote
Old 08-03-2004, 03:10 PM   #2
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

this is a weird one. even though i trace the length of the selection array after assigning it, and it gives me 1, when looking at the ide my selection had not changed from the fill that was selected. i think your best bet is to take this to the extendFlash list run by flashguru (flashguru.co.uk) or the extending flash forum, where you will have more people than me looking at it.
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 08-17-2004, 04:17 AM   #3
cMan
Registered User
 
Join Date: Apr 2004
Posts: 28
Default

Code:
function allNamesToLower()
{
  var currentDoc = fl.getDocumentDOM();
	
  for( var i = 0; i < currentDoc.timelines.length; i++ )
  {
    var myCurrTimeline = currentDoc.timelines[ i ];
    for( var j = 0; j < myCurrTimeline.layers.length; j++ )
    {
      var myCurrentLayer = myCurrTimeline.layers[ j ];
      for( var k = 0; k < myCurrentLayer.frames.length; k++ )
      {
        var myCurrentFrame = myCurrentLayer.frames[ k ];
        for( var l = 0; l < myCurrentFrame.elements.length; l++ )
        {
          var myCurrentElement = myCurrentFrame.elements[ l ];
					
          // Here's the simple code to change the name to lower case.
          var newName = myCurrentElement.name;
          myCurrentElement.name = newName.toLowerCase();
          
        }
      }
    }
  }
}
cMan is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:08 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.