Ted Patrick - Demos & MAX @ Adobe Systems


Note: This is the personal blog of Ted Patrick. The opinions and statements voiced here are my own.



Relative Paths in JSFL

DIGG IT!     9 Comments Published Tuesday, March 22, 2005 at 1:59 PM .

So I cracked open JSFL and the first problem was finding the current path. I searched the JSFL documentation, searched online, IM'ed Guy Watson, no answers, NADA. Here how to do it, it is really difficult!&

Path names in JSFL use the file:/// style format. To open a file named "example.fla" relative to the executing JSFL script, you simply say:

fl.openDocument( 'file:///example.fla' );


Simple ehh, that magic took at an hour to figure out.

There are some killer things you can do with JSFL.

//open a file named example
fl.openDocument( 'file:///example.fla' );

//insert the V2 button components
fl.componentsPanel.addItemToDocument({x:0, y:0}, "UI Components", "Button");

//delete the instance added to the stage
document.deleteSelection();


Just remember when you want to use files in a relative path to the JSFL script, just use file:/// and you are working in the same path as the JSFL script.

Cheers,

Ted ;)

9 Responses to “Relative Paths in JSFL”

  1. # Blogger gandalf

    Wish you would have contacted me - use JSFL in a build script to build tons of FLAs and then save the SWFs in a location sep. from the source.  

  2. # Anonymous bokel

    Take care Ted:
    The path is not relative to the jsfl but to the ide's idea of the current path. Whenever you save something from the ide, the current path is changed to the path you saved to.  

  3. # Blogger Ted Patrick

    Ralf,

    I thought so too, but it seems puzzling to me why this example works so well.

    The examples opens 3 consecutive FLA documents all via relative path from the JSFL file.

    http://www.powersdk.com/download/JSFLTest.zip

    I am simply noting that the use of "file:///" is by defualt relative to the executing JSFL file. Otherwise the above example would not work.

    Cheers,

    Ted ;)  

  4. # Blogger Ted Patrick

    Note: On the example, the ZIP file has nested folders, if you simply grab the files out, it will fail. If you uzip to the paths, it works fine.

    Ted ;)  

  5. # Anonymous bokel

    It works ok, if the ide isn't running, otherwise it may fail because of the ide's current path.

    O Mother, please give us headless flash.  

  6. # Blogger Ted Patrick

    This post has been removed by a blog administrator.  

  7. # Blogger Ted Patrick

    Got it. So if the IDE has a file context, the value of file:/// is modified to the open path. Thanks Ralf!

    This makes sense but there should be a simple property for the script path vs the document path.

    Ted ;)  

  8. # Blogger Robert

    It's two years later, but there is a new JSAPI in Flash CS3:

    fl.scriptURI


    Description
    Read-only property; a string that represents the path of the currently running JSFL script, expressed as a file:/// URI. If the script was called from fl.runScript(), this property represents the path of the immediate parent script. That is, it doesn't traverse through multiple calls to fl.runScript() to find the path of the original calling script.  

  9. # Blogger Philipp

    And again two years later...

    I had the same problem but it didn't work with file:///example.fla. I had to use file:///./example.fla instead.

    I didn't try the fl.scriptURL but "./" seems easier anyway.  

Post a Comment

Where to find me:

Ted on Twitter - @AdobeTed
Ted on Adobe Groups
Ted on LinkedIn
Ted on Facebook
Ted at Adobe


Latest

Lists

Links

Jobs

Flex Jobs
city, state, zip

Archives