PDA

View Full Version : looping through selected frames


Ingo
09-26-2005, 10:52 AM
Hi,

I need to loop through the selected frames. It turns out that if one selects frames, the document.selection array will contain the objects on the selected frames, not the frames themselves. How do I get the selected frames instead?

For a given symbol instance "myInstance", how do I get the layer where myInstance lives?

Ingo

flatface
09-30-2005, 12:28 PM
read the help section under "timeline.getSelectedFrames()"

you can loop through the selected frames with a bit of code like this

var curr_doc = fl.getDocumentDOM();
curr_doc.selectNone();
var curr_tl = curr_doc.getTimeline();
var selectedframes = curr_tl.getSelectedFrames();

if (selectedframes.length!=0){

for (var i=0; i<selectedframes.length/3; i++){
for (var j=selectedframes[i*3+1]; j<sselectedframes[i*3+2]; j++){
if (j<curr_tl.layers[selectedframes[i*3]].frameCount){
//this is each frame
curr_frame = curr_tl.layers[selectedframes[i*3]].frames[j];

// now do your code to each frame





// this code then skips on to the next key frame (optional)
j += curr_frame.startFrame + curr_frame.duration-1;
}
}
}
}

//deselect frames (optional)
curr_tl.setSelectedFrames([]);




as for getting the layer of a instance

there is a new property in flash 8 - element.layer

so if you have:

var curr_element = curr_doc.selection[0];
var element_layer = cur_element.layer;

Ingo
09-30-2005, 01:41 PM
Thanks!!

Ingo

flatface
09-30-2005, 01:45 PM
no prob,

just noticed a typo remove the bolded letter:

for (var j=selectedframes[i*3+1]; j<sselectedframes[i*3+2]; j++){

good luck!