0

I want to write a script that replaces the source of certain bitmap objects in my library with another file. Actually, it's not important that the object is updated on the stage in Flash, and I don't care if BitmapItem.sourceFileIsCurrent's state changes. I just need the sourceFilePath to be changed for our export process (involving CreateJS).

The problem is that JSFL's BitmapItem.sourceFilePath is read-only. I considered importing the new image and deleting the old one, but the old one will be used in various other symbols and on the stage. So what can I do to resolve this?

PokeJoe
  • 57
  • 1
  • 7

1 Answers1

0

I haven't used Flash in a while so not 100% sure this will work.

First you can try this:

  1. Replace/update the path of an Bitmap item on the library manually
  2. Check the History Panel and see if the action is recorded and does not have a red x on it's left. If it doesn't, you're in luck, you an use the Panel's options(3 horizontal lines) to change the view to a javascript one and see the call you need to make

Not everything you do in the IDE can be done with JSFL though.

Another idea you can try is:

  1. store the name of the library item you want to replace
  2. import the new bitmap you want to use (via fl.getDocumentDOM().importFile())
  3. delete the old bitmap item you wanted to replace from the library
  4. set the previously stored name to the new bitmap item(via the name property)
  5. (optionally) update instances (instanceUsingOldBitmap.libraryItem = newBitmapItem)
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Thanks for the ideas. Some issues: the history panel does give some code, but it's apparently not relevant. `var lib = fl.getDocumentDOM().library; lib.setItemProperty('allowSmoothing', false); lib.setItemProperty('compressionType', 'photo');` The second idea fails at step 3 - if I delete the old bitmap, references to it on the stage or in other symbols disappear. – PokeJoe Feb 03 '14 at 03:07
  • However, using the JSFL exposed through the history window (which I didn't know about heretofore, thanks) - I discovered `fl.getDocumentDOM().swapElement();` which may help solve this problem. – PokeJoe Feb 03 '14 at 03:12
  • Forgot about the the issue with symbols disappearing. Glad `swapElement()` popped up and that history step can be called from JSFL (as I mentioned not everything you do in the Flash IDE can be replicated in JSFL) – George Profenza Feb 03 '14 at 10:49