今天在做一個從Fla導出PNG的東東時,要用到fl.findObjectInDocByType函數,但是一運行自己寫的JSFL時,居然說fl.findObjectInDocByType不是一個函數。憑直覺這應該是函數未定義好。果然,在找了半天之后,找到這個文章幫了大忙。大概就是說要手動添加運行代碼,使定義fl.findObjectInDocByType的JSFL代碼的運行。我是照着最后一個大哥說的做的,就是在自己的JSFL里添加了:
if( fl.findObjectInDocByType == null ){
fl.runScript( fl.configURI + “Javascript/ObjectFindAndSelect.jsfl” );
}
用這一招是最靈的了。
再看一看fl.findObjectInDocByName()函數。幫助文檔上說得清清楚楚:
用法
fl.findObjectInDocByName(instanceName, document)
參數
instanceName 一個字符串,指定在指定文檔中某項的所有或部分實例名稱。
document 要在其中搜索指定項的 Document 對象。
雖然說instanceName 是可以指定在指定文檔中某項的所有或部分實例名稱,但是經過實驗,只能取得實例名稱完全匹配的元件,打開
ObjectFindAndSelect.jsfl
文件查找到91行FlashUtils_findObjectInTimelineByName,將108行的if (items[l].name == objName)改為if (items[l].name.match(objName))就可以了。
具體原因當然都很簡單了!
////////////////////////
上面說的那篇文章內容如下(怕以后刪了找不着):
Bug in JSFL fl.findObjectInDocByType in Flash CS3
March 6th, 2008
Goto comments Leave a comment
New CS3 JSFL library’s are broken which would have been great to have. I tried to use the new finObjectInDocByType and I even used the example provided in the livedocs and it crashes. Maybe this was not implemented for AS3? I hope this gets fixed soon we could do some rad stuff! Adobe use the bug system that you have for Flex for Flash too!
******BUG******
Concise problem statement:
fl.finObjectInDocByType crashes in the example given in live docs.
Steps to reproduce bug:
Create a JSFL script and place it in your commands directory like other jsfl code.
Copy and past the first example from livedocs for finObjectInDocByType
Create a flash as3 fla file and place a text field on the stage.
command -> script name
you will get an error stating: At line 64 of file “ObjectFindAndSelect.jsfl”: TypeError: nextSymbolItemObj has no properties.
ShareThis
Flash Platform, jsfl
Comments (5) Trackbacks (0) Leave a comment Trackback
Vincy
July 18th, 2008 at 07:29 | #1
Reply | Quote
This error can be resolved by following these simple steps:
1) Go to the following location:
C:\Documents and Settings\ocal settings\application data\adobe\flash cs3\en\configuration\javascript (windows xp):
2) Open “ObjectFindAndSelect.jsfl” file.
3) Copy and paste the following code at line number 29:
if (objTimeline == undefined) {
return
}
4) Close flash CS3 and restart again, things should work fine.
Vincy
July 18th, 2008 at 07:41 | #2
Reply | Quote
Just a point I forgot to mention:
Copy the JSFL file which uses “fl.findObjectInDocByType” command to the /Commands directory and then try running the command from the Commands menu.
Rost
March 13th, 2009 at 09:39 | #3
Reply | Quote
Vincy, your tips are brilliant. Helped me to fix my “fr.Find in Flash” Search panel completely.
I’d add a bit to your second comment:
It seems the “ObjectFindAndSelect.jsfl” file is executed automatically each time you run your JSFL code from the Commands menu.
But, if you run, for example, a JSFL file from your Flash Panel, the “ObjectFindAndSelect.jsfl” is not run automatically, so its functions like fl.findObjectInDocByType won’t be visible from your code.
To workaround this, just run the needed file before running your code:
fl.runScript( fl.configURI + \”WindowSWF/fr.findTextFromPanel.jsfl\
And its functions will start working for your flashpanel.
Thanks,
Rost
David Goodman
August 19th, 2009 at 09:54 | #4
Reply | Quote
I was wondering Rost, could you give me an example of how to fix the ObjectFindAndSelect.jsfl problem from the WindowSWF I am stuck on this and I’m unable to work out what to do from your comment.
My AS3 class that is linked up to the WindowSWF calls on a button click
MMExecute(“fl.runScript(fl.configURI + ‘Javascript/ObjectFindAndSelect.jsfl’);”)
MMExecute(“fl.runScript(‘file:///C|/svn/Flash/jsfl/brandLanguageConfigTools.jsfl’, ‘skinFile’,\”" + strToPass + “\”,\”" + cbFLA.selectedItem.label + “\”);”);
The 2nd MME has the fl.findByName call which causes the error, I also put the fl.runScript(ObjectFindAndSelect.jsfl) call inside the functions of that JSFL hoping that would get it working but no cookie :( any help?
thanks
slopps
June 3rd, 2011 at 10:20 | #5
Reply | Quote
Also, simply adding this code before you call findObjectInDocByType will fix it:
if( fl.findObjectInDocByType == null ){
fl.runScript( fl.configURI + “Javascript/ObjectFindAndSelect.jsfl” );
}
I found that in a comment for the CS4 livedocs.
