rulururu

post Focus on stage element via JSFL

October 8th, 2009

Filed under: JSFL — Alex Bylim @ 7:15 pm

Just imagine you are creating some custom panel for Adobe Flash CSx, and you want to find some element on stage or in some symbol. Ok, you can easily find it through JSFL DOM, but what’s next ? You’d probably want to make it selected, ok, code below will select element by instance name:

// getting all elements on the stage
var myElements = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements;
// looping through all elements
for (var i=0; i < myElements.length; i++)
// check if element's name is what we want
  if( myElements[i].name == "element_name"){
    // clear selection
    fl.getDocumentDOM().selectNone();
    // make element selected
    myElements[i].selected = true;
    // as we found our element then quit the loop
    break;
}

Good, now our element is selected. But how can we make it be visible to user and in the center of our stage ? To achiev this we need to use zoomFactor:

Code below will force Adobe Flash IDE to show selected element in the center of  the stage window:

  fl.getDocumentDOM().zoomFactor +=  1;
  // leave zoomFactor unchanged
  fl.getDocumentDOM().zoomFactor -=  1;

For more detail info about JSFL API you can visit this link: http://help.adobe.com/en_US/Flash/10.0_ExtendingFlash/index.html

ruldrurd
Powered by WordPress, Web Design by Laurentiu Piron
Entries (RSS) and Comments (RSS)