PDA

View Full Version : Determining the Layer value of a selected element.


Cyd
05-05-2006, 03:10 AM
Im trying to make a command that will allow me to add a keyframe at the current frame, but only on the layers of which I have an element selected within the workspace.

As in, I select a bunch of elements on the screen, and I hit a button and only the layers that house those elements are given a keyframe on that current frame.

Now my problem is that I cant seem to find a property to lookup on the selection[0] that will determine this elements current layer -- in fact, I cant seem to find any property to lookup the current layer,

Im using: fl.getDocumentDOM().selection[0]. ??? but there isnt a
fl.getDocumentDOM().selection[0].layer or anything of this sort.

Can anyone help?

Cyd
05-05-2006, 05:20 AM
Found a quick solution. I defined the selection instead of choosing the layer -- it does the same thing in the end.

For any that are interested, here you go.

//
// Key Selected
// -Copyright 2004, Chris Fourney
//
//

selectedfrms = fl.getDocumentDOM().getTimeline().getSelectedFrame s();
currframe = fl.getDocumentDOM().getTimeline().currentFrame;


looper = selectedfrms.length;


newselection = new Array(looper);

a = 0;

for (var i = 0; i < (looper-1); i++) {
newselection[i] = new Array(3);

for (var j = 0; j < 3; j++) {

if (j == 0){
newselection[i][j] = selectedfrms[a];
//LEAVE IT! This is the layer.
}

if (j == 1){
newselection[i][j] = currframe;
}

if (j == 2){
newselection[i][j] = currframe + 1;
}
a++;

}
}



vara = newselection[0][0];
varb = newselection[0][1];
varc = newselection[0][2];

alert(vara + ":" + varb + ":" + varc);

vara = newselection[1][0];
varb = newselection[1][1];
varc = newselection[1][2];

alert(vara + ":" + varb + ":" + varc);

vara = newselection[2][0];
varb = newselection[2][1];
varc = newselection[2][2];

alert(vara + ":" + varb + ":" + varc);

for (var i = 0; i < (looper-1); i++) {

vara = newselection[i][0];
varb = newselection[i][1];
varc = newselection[i][2];

if (i == 0){
fl.getDocumentDOM().getTimeline().setSelectedFrame s([vara, varb, varc], true);
}
else{
fl.getDocumentDOM().getTimeline().setSelectedFrame s([vara, varb, varc], false);
}

}

Cyd
05-05-2006, 12:01 PM
Fixed a few bugs, this allows for any number of layers now.


//
// Key Selected
// -Copyright 2004, Chris Fourney
//
//

selectedfrms = fl.getDocumentDOM().getTimeline().getSelectedFrame s();
currframe = fl.getDocumentDOM().getTimeline().currentFrame;


looper = (selectedfrms.length)/3;

fl.trace(looper);



newselection = new Array(looper);

a = 0;

for (var i = 0; i <= (looper-1); i++) {
newselection[i] = new Array(3);

for (var j = 0; j < 3; j++) {

if (j == 0){
newselection[i][j] = selectedfrms[a];
//LEAVE IT! This is the layer.
a++;
}

if (j == 1){
newselection[i][j] = currframe;
a++;
}

if (j == 2){
newselection[i][j] = currframe + 1;
a++;
}

}
}


for (var i = 0; i <= (looper-1); i++) {
vara = newselection[i][0];
varb = newselection[i][1];
varc = newselection[i][2];

fl.trace(vara + ":" + varb + ":" + varc);
}


for (var i = 0; i <= (looper-1); i++) {

vara = newselection[i][0];
varb = newselection[i][1];
varc = newselection[i][2];


if (i == 0){
fl.getDocumentDOM().getTimeline().setSelectedFrame s([vara, varb, varc], true);
}
else{
fl.getDocumentDOM().getTimeline().setSelectedFrame s([vara, varb, varc], false);
}

}



fl.getDocumentDOM().getTimeline().convertToKeyfram es();

//KEY IT!!

krayzeebean
05-05-2006, 10:14 PM
You don't even need to make a custom command for that, it's part of standard Flash and has been for ages. Just use the Insert Keyframe command (insert->timeline->insert keyframe), it does exactly the same thing. I reassigned the the F6 shortcut to that since I rarely use Convert to Keyframes.

Cyd
05-06-2006, 09:46 PM
I was using it within a tool I programmed. I was unable to find a similar thing for a tool, so I used this, but apparently this also exists in timeline.insertKeyframe();

Well then, that wouldve saved time.
Regardless, I needed to dissect that to also figure out the layers for other purposes.

Good stuff, thanks.

-Chris

Cyd
05-06-2006, 10:46 PM
Only problem is that the built in function deselects whatever is keyframed. Mine keeps the selection -- which is necessary in the tool Im making.