tags:

views:

17

answers:

1

I'm looking for a jsfl function that can select all items on a frame and delete all strokes that match a specific color such as #0000ff

Basically I make a lot of notes with the pencil tool using red pencil strokes. But when Im done I just want to tell flash to delete all my red stokes from the screen and leave everything else intact. Any solutions to this?

A: 

Good question !

Looking at the Document object in the JSFL documents I see the only way to retrieve a Stroke is through document.getCustomStroke() which is annoying. Ideally the Shape Object would store Stroke and Fill information, but it doesn't :(

I tried to control the selection using arrays:

var doc = fl.getDocumentDOM();
doc.selectAll();
var s = new Array().concat(doc.selection);
var sl = s.length;
doc.selectNone();

for(var i = 0; i < sl ; i++){
   doc.selection = s[i];
   stroke = doc.getCustomStroke('selection')
   fl.trace(stroke.color)
}

That didn't work.

Then I tried to select each object using

doc.mouseClick({x:s[i].x, y:s[i].y}, false, false);

but that's not very helpful as the notes can take any shape, so a click at the note's top left corner might be a missed selection. Looping through each pixel just to get a selection wouldn't work.

Short answer is not because the only way to retrieve the stroke color is through the document selection.

There are some workarounds though:

  1. In the IDE, use Find and Replace, choose Color instead of Text and replace your note color with something transparent. Unfortunately this isn't much of a solution. It will just hide the notes, not delete them. flash find and replace

  2. Make it easy to get the notes from jsfl: Place all the notes in the current timeline in one layer and give it a suggestive name, say '_notes', then just delete that layer.

e.g.

var doc = fl.getDocumentDOM();
if(!doc) alert('Pardon me! There is no document open to work with.');

fl.trace(deleteLayerByName('_notes'))

/*Returns true if the layer was found and deleted, otherwise returns false*/
function deleteLayerByName(name){
    var timeline  = doc.getTimeline();
    var frame     = timeline.currentFrame;
    var layers    = timeline.layers;
    var layersNum = layers.length;
    for(var i = 0 ; i < layersNum; i++){
        if(layers[i].name == name){
            timeline.deleteLayer(i)
            return true;
        }
    }
    return false;
}

Hopefully someone can provide a nice hack for selecting objects by colour in jsfl. There are quite a few things you can do in the IDE, but can't do them from JSFL :(

HTH

George Profenza
Yeah it seems like it should be a pretty basic operation but man it just doesn't seem possible based n the capabilities of jsfl itself.
Ibis
@Ibis jsfl can be quite annoying sometimes. Great to see the flashfilmmaker.com site alive and kicking btw :)
George Profenza