project paths?
  • HughCHughC March 2012

    This is not so much a xJSFL thing as a JSFL one. I've written a snippet, and I want to hand it over to an animator friend, so that he can run it. The script uses the Template class and generates XML and class files from templates, which are tucked away in a /src/templates/ dir within our project. They in turn write out files to /src/classes and /bin/xml directories.

    The Template docs ( http://www.xjsfl.com/support/api/text/template ) cite this example for saving a template:

    template.save(projectURI + 'src/' + package + '.as', true);

    There's a ref above to 'projectURI ' but I can't find any reference to it (or indeed projects, as objects at all) in the Extending CS5 docs. Then I turned up an Adobe note, that says they were dumped under CS4. Handy.

    Currently I'm using a path relative to the current open file, but I want the snippet to work regardless of which fla within our project he and I are in. Can anyone suggest a simple way to set / get a path to a 'project folder' under which all paths are then relative? 

  • DaveDave March 2012

    Ah sorry, that's obviously a bit ambiguous. There's been so many docs to write I don't always make them ctystal clear.

    I was probably implying that it was the project URI of your AS project. xJSFL doesn't have any concept of "projects".

    And, as from the Beta 1, it's now "pathOrURI" which means it can be anything from

    • an absolute uri "file:///c|/path/to..."
    • a path "c:/path/to..."
    • a relative path "path/to..."
    • a path token "{user}/assets/templates/..."

    Also, there's new URI grammar which has not been documented yet:

    • "/path" the current path (core, module, user) root
    • "//path" - the xjsfl root
    • "///path" - the drive root

    This is similar to how web servers work. "/" refers to the "public" root, but not the actual physical server root. This is the same in xJSFL. So if you are working in the user folder, "/" will always refer to "xJSFL/user/".  a bit easier than always typing out xjsfl.uri + 'user/..." or "{user}...". And if you are in a module, "/" will refer to the current module root.

    You can also set your own custom tokens.

    xjsfl.settings.folders.set('projectName', 'file:///path/to/folder/')

    Then, in future you can just write:

    var file = new File('{projectName}/some file.txt');

    This is mainly useful for when you need to save folders to text or config files. Snippets uses this to save Snippets paths:

    <set name="Commands Folder" uri="{flash}Commands/"/>

    The new URI class handles ALL this functionality so you, as the user, don't need to think about it. All you need to know are a few basic, then you have the flexibility to get going.

    Load up the "Code Examples" Snippets set, then navigate down to URI and run the snippets there. It shoudl (as far as I remember) dump out a load of test cases and should make it clearer for you.

    As far as I know, it's all pretty robust, but obviously having this out in the wild will prove if it works or not!

    So, in answer to your question, the user folder is probably the best-bet "relative" folder you'll want

    xjsfl.uri + 'user/path/to/file.txt';
    '{user}/path/to/file.txt';

    Hope that helps.

    :D

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID Sign In with Google Sign In with Twitter

Sign In Apply for Membership

Tagged