Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

fl.findObjectInDocByName() Just doesn't seem to work at all. Am I missing something?

Explorer ,
Aug 16, 2020 Aug 16, 2020

I have a clean Animate file. 
One graphic object in the library "blueCircle".

and one instance of that object on the main timeline.

I copied the code directly from the documentation.

It fails everytime. 
Am I missing something or is fl.findObjectInDocByName(); no longer supports?

PLEASE HELP!!! I will buy you cookies!

 

var nameToSearchFor = "blueCircle";
var doc = fl.getDocumentDOM();
var results = fl.findObjectInDocByName(nameToSearchFor, doc);
if (results.length > 0) {
alert("success, found " + results.length + " objects");
}
else {
alert("failed, no objects named " + nameToSearchFor + " found");
}

 

 

549
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Aug 18, 2020 Aug 18, 2020

As a side suggestion:
If you want to find an instance of a specific symbol by name (not instance name, but symbol name), you can refer to instance's property called libraryItem. It stores a reference to the real symbol in the library, that the particular instance represents. So, to find all the instances of the symbol blueCircle, you can use:

 

 

function selectInstancesBySymbolName( symbolName ){
	
	// Deselect all in the current frame
	fl.getDocumentDOM().selectNone();
	
	var timeline = fl.getDocu
...
Translate
Engaged ,
Aug 17, 2020 Aug 17, 2020

I think that this method looks for movie clip instances only. Graphic instances don't have names, so you can't search them by name. In your example, if you change the instance type to "Movie Clip" and assign it an instance name "blueCircle", the method will find the instance.


- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2020 Aug 17, 2020

Thankyou SO Much for clarifying this!
I couldn't find any answers in the documentation. 

Is there a way to find a specific Graphic Symbol on the stage by name?

Basically I'm writing a script that changes the FirstFrame of the Head symbol, and then adjusts the "nose" position accordingly. 
But all the symbols have to remain Graphic symbols.
Somthing like:

function HEADANGLE(mousePosX, mousePosY) {

newFirstFrame = mousePosX - mousePosY;
fl.getDocumentDOM().HEADSYMBOL.setElementProperty('firstFrame', newFirstFrame);

//search and select "nose" Graphic symbol:
var nameToSearchFor = "nose";
var doc = fl.getDocumentDOM();
var results = fl.findObjectInDocByName(nameToSearchFor, doc);
if (results.length > 0) {
alert("success, found " + results.length + " objects");
}
else {
alert("failed, no objects named " + nameToSearchFor + " found");
}

//Move nose accordingly:
nose.moveX ++;
nose.moveY ++;

}




Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2020 Aug 17, 2020

Ok I think I have a work around:

My layer names should be correct so....
I can cycle through all the layers and lock all the others and selectAll. 
Then I can manipulate the selected graphic symbol from there. 

//////////////////////////Select the right Layer Function:
	function SELECTLAYER(layerName) {
		
		var timeline = fl.getDocumentDOM().getTimeline();
		
		//cyle through all the layers and then cycles through all the layer names. If they match, unlock the layer and lock everything else. 
		for (var i = 0; i < timeline.layerCount; ++i) {
			fl.trace("layerName========= "+ layerName[i]);
			//Lock the layer...
			fl.getDocumentDOM().getTimeline().layers[i].locked = true;

			//cycle through the layer names. 
			for (j = 0; j < timeline.layerCount; j++) {
				//fl.trace("In FLA layerNames========= "+ timeline.layers[j].name);
				//fl.trace("in TXT layerNames========= "+ layerNames[i]);
				//if there's a match Unlock the layer.
				if (timeline.layers[i].name == layerName) {
					fl.getDocumentDOM().getTimeline().layers[i].locked = false;
					fl.trace("MATCH!!!  " + timeline.layers[i].name + " <is> " + layerName);
				}
			}
		}
		//select all unlocked items.
		fl.getDocumentDOM().selectAll();
		
		
		
	}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 18, 2020 Aug 18, 2020

Hi,

It's good that you found a workaround!
Below is an optimized variant of your function - with one cycle less and early exit from the loop.

function selectLayerByName( layerName ){
	
	var timeline = fl.getDocumentDOM().getTimeline();
	
	// Select all layers
	timeline.setLayerProperty( "locked", true, "all" );

	// If the layer's name matches the parameter, unlock it
	for ( var i = 0; i < timeline.layerCount; i++ ){
		
		if ( timeline.layers[ i ].name == layerName ){
			
			timeline.layers[ i ].locked = false;
			
			fl.trace( "MATCH!!!  " + timeline.layers[ i ].name + " <is> " + layerName );
			
			// If we suppose that there is no duplicated layer names
			// in the timeline, we can skip the rest of the loop			
			break;
		}
	}
	//Select all unlocked items.
	fl.getDocumentDOM().selectAll();
}

selectLayerByName( "blueCircle" );
- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 18, 2020 Aug 18, 2020

As a side suggestion:
If you want to find an instance of a specific symbol by name (not instance name, but symbol name), you can refer to instance's property called libraryItem. It stores a reference to the real symbol in the library, that the particular instance represents. So, to find all the instances of the symbol blueCircle, you can use:

 

 

function selectInstancesBySymbolName( symbolName ){
	
	// Deselect all in the current frame
	fl.getDocumentDOM().selectNone();
	
	var timeline = fl.getDocumentDOM().getTimeline();
	var i, cf = timeline.currentFrame, myFrame, j;
	

	for ( i = 0; i < timeline.layerCount; i++ ){
		myFrame = timeline.layers[ i ].frames[ cf ];
		for( j = 0; j < myFrame.elements.length; j++ ){
			if( myFrame.elements[ j ].libraryItem.name === symbolName ){
				myFrame.elements[ j ].selected = true;
			}
		}
	}
}

selectInstancesBySymbolName( "blueCircle" );

 




- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 18, 2020 Aug 18, 2020
LATEST

I have no idea how to thankyou!!!
This is a breath of fresh air!!!
Thankyou thankyou thankyou!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines