20 Replies Latest reply on Aug 17, 2006 10:05 AM by Newsgroup_User

    Simple openFile script

    jumpOnCommand Level 1
      I'm completely new to Director, but fairly fluent in Flash Actionscripting, which as I've found, it quite different.

      I've been playing about with ebooks, online tutorials and this forum trying to construct something, but to no avail. I would like to open a simple file. test e.g.

      function mouseUp(me) {
      button1.openFile("C:/autorun.inf", 1)
      }

      when I run the script, I get an error saying "button1 is not defined ".

      Help would be greatly appreciated.

      jumpOnCommand
        • 1. Re: Simple openFile script
          Level 7
          A function like you have written would normally be in a behavior script
          window. That behavior would then be attached to a sprite, your button,
          for instance.

          You don't say how button1 is defined. If its a named sprite that holds
          this behavior then you don't need the reference. Me refers to the sprite
          that holds the behavior. Me is in most respects, very similar to "this"
          in actionscript.

          If button1 is the name of a sprite other than the sprite that holds the
          behavior, then you would refer to it like this:

          sprite("button1").

          In any case, the name of a sprite is a string. If you don't name the
          sprite then its channel number is a number.

          If button1 is a cast member's name, then you don't normally refer to the
          member name in that way.

          OpenFile() is a fileIO xtra function. You need to create an instance of
          the xtra before you can call it's functions. If button1 is the name of
          the xtra's instance, then it may be out of scope. In order for it work
          in your example, button1 would have to be a global or property variable.

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/
          • 2. Re: Simple openFile script
            jumpOnCommand Level 1
            wow... I understood not a single thing of what you just said. Director really is quite difficult.

            While I'm still pottering about Director trying to find this green wrinkley sprite everyones talking about, would you mind either pointing me, or write me a quick example of how I would open an *.exe file? I believe its something like this:

            _player.open("C:/notepad.exe")

            Thank you for your help

            jumpInCommand
            • 3. Re: Simple openFile script
              Level 7
              Assuming that notepad is indeed in the root of your C:\ drive (which it
              is normally not), you would do this (you had it real close, but had the
              wrong slash):

              _player.open("C:\notepad.exe")
              • 4. Re: Simple openFile script
                jumpOnCommand Level 1
                Sorry to sound simple, but where exactly was it I actually put this? I slowly getting my head around this sprite - behaviour system, but somehow I'm going wrong. I think I'm trying to use it like Flash.

                In Flash I used to write all my script in that _root. But in Director I can't find it. :)

                Could someone start my from a blank movie where this bit goes, please

                Thanks Mike.
                • 5. Re: Simple openFile script
                  jumpOnCommand Level 1
                  Ahh, yes, sorry. I think I was just getting in a muddle. I'm sure I'll lose how to get to it again, but were there now, thats what matters :)

                  I can get this script to run fine:
                  on mouseUp
                  _player.open("C:\notepad.exe")
                  end

                  My idea was to run this from a CD, loading the choosen folder from the CD. (I have successfully done this now.) However, I can't get it to load something from my desktop (if that WAS where I wanted to go), I read its something to do with needing FileIO?

                  Thanks all

                  • 6. Re: Simple openFile script
                    Level 7
                    In Flash you can write actionscript into either a frame script space or,
                    to a limited extent, right on the object that you want use.

                    In Director you normally write your code as a behavior and then attach
                    that behavior to any number of sprites in the score. You can also write
                    behavior style functions into the frame script space in the score.
                    Additionally, you can write movie wide functions into movie script
                    windows. There are two script window types, behavior and movie.

                    Code that you write into a movie script is not attached to anything and
                    has no direct connection to either the stage or the score. In a movie
                    script window you can write any number of functions, and use as many
                    windows as you like. This is somewhat similar to writing actionscript
                    into a movie frame space.

                    Any original content for a Director movie is placed into a cast. Every
                    cast member has the same precedence. There is no heirarchical structure
                    to Director assets as there is in Flash. Any cast member that is placed
                    on the stage, or in the score, is an instance of that cast member and is
                    called a sprite. You can only place one cast member instance in any
                    sprite channel at any given frame. This is very differnt from Flash
                    where you can place every asset into the same layer.

                    Every sprite is self aware and self referential. It does not need to be
                    assigned as a "button" or a "symbol" in order to be controlled. It does
                    not need to be named in order to be addressed. A sprite does not need to
                    be in the first frame of the score in order for Lingo to recognize it.

                    Behavior code is usually written so that it can be assigned to any
                    number of sprites. For instance, you can write one:

                    on exitFrame
                    go to the frame
                    end

                    function. And then use that throughout the score to stop the playback
                    head. In Flash you have to write an individual stop(); function in any
                    keyframe where you want to stop the playback head.

                    If you want to open an executable from a user action in your movie, you
                    would:

                    1. create the button artwork. If you want a complex button, you'll have
                    to create one cast member for each state of the button.

                    2. To operate the button, you can use one of the behaviors in the
                    Library. You can also use one of these behaviors to have the cursor
                    change. Attach these behaviors to the button sprite by dragging it from
                    the Library to your sprite on the stage. If there are settable parameter
                    values needed, then a window will open.

                    3. To have this button call that executable, open the behavior that you
                    attached and find the "on mouseUp me" function. Then you can add the
                    open() function call to that function. If you need to find the user's
                    desktop from your projector, you can use any of the OS xtras. BuddyAPI
                    and fileXtra4 are the most popular. Each one comes with instructions.

                    Most of this is covered in the tuturials that come with Director. You
                    may want to look at those.

                    --
                    Rob
                    _______
                    Rob Dillon
                    Adobe Community Expert
                    http://www.ddg-designs.com
                    412-243-9119

                    http://www.macromedia.com/software/trial/
                    • 7. Re: Simple openFile script
                      kyleg
                      not sure if this will help you, but I have a flash vs director section on my site that I wrote as well as Lingo to Actionscript translator (which will go both ways)

                      not really an app as much as it is a guide...you'll see

                      hope this helps

                      http://www.foreveryoursmedia.com/directorshowcase/index.htm
                      • 8. Re: Simple openFile script
                        jumpOnCommand Level 1
                        Thank you both for you help. After spending a few hours/days blurrly staring at the screen, some of this is starting to make sence.

                        Kyleg, I thought your website was very good. I read the Flash v Director, I couldnt agree more. I'd hate to sound like the new-comer complaining, but there are alot of differences between the two packages which I don't yet see why. They both have some great features, but from a guess, Directors scripting is most likely a simplified version of Flash (like Flash is of C++). I only say this becuase if Lingo was a better (more complex) language to script with, then Flash would certainly use the better of the two.

                        Rob, what you said does make sence, I think I will be able to get my head around where scripts are to be placed now.

                        BTW: Kyleg, in your translator, I think Directors 'property list' is a comparison to Flash's 'array'... not that I know what a property list, but they look similar.
                        • 9. Re: Simple openFile script
                          Level 7
                          Actually Lingo is a much more elegant and useful scripting language than
                          Actionscript. Lingo was based on Apple's hypercard scripting, which was
                          based on Basic. Actionscript is based on Javascript.

                          Lingo's property lists are similar to Actionscript associative arrays,
                          but are infinitely simpler to use. Lingo lists are similar to
                          Actionscript arrays, but, again are simpler to use.

                          --
                          Rob
                          _______
                          Rob Dillon
                          Adobe Community Expert
                          http://www.ddg-designs.com
                          412-243-9119

                          http://www.macromedia.com/software/trial/
                          • 10. Re: Simple openFile script
                            jumpOnCommand Level 1
                            I'll let you know when its getting simplier ;)

                            Here's another one for you, which we're on the topic of openFile. It's reading from my CD fine now using;

                            open the moviePath & ("subfolder\setup.exe") -- and also the suggested "notepad.exe"

                            However when I ask it to load up another file in the same folder, it doesn't work. tested files include:

                            autorun.exe
                            autorun.inf
                            software.htm
                            main-banner.jpg

                            Any idea why it would like these files, but it's fine openning published files and notepad.exe?

                            Thanks for all the help.
                            • 11. Re: Simple openFile script
                              Level 7
                              The open command can ONLY open .exe files. It will always fail with
                              inf, htm, or jpg files. It only opens executables. I don't know why it
                              failed to open your autorun.exe file. Are you sure that it didn't?
                              Does that autorun.exe file need to be fed some sort of command line
                              switch in order to do what it is meant to? Perhaps it did open, but
                              then shut down real quick because it wasn't given the correct input.
                              Does it do anything if you just doubleclick on that file in Explorer?
                              • 12. Re: Simple openFile script
                                jumpOnCommand Level 1
                                Your right, it doesn't appear to do anything the autorun.exe...

                                ...infact> an autorun.inf launches autorun.exe which appears to launch index.htm. However, if you simply launch autorun.exe it does nothing...

                                back to the point, yes, your totally right. Now my next question would be the grand finalie. What operation should I use to open an non-executable file.

                                I've already looked at the methods, but 'open' looked just right. Which one should I use a .htm file?

                                Thanks..again. :)
                                • 13. Re: Simple openFile script
                                  Level 7
                                  Director can't do that on its own. Actually it can with open..with, but
                                  that is generally a lot more effort than it's worth. I would use the
                                  BuddyAPI xtra (www.mods.com.au/budapi). There is a command called
                                  baOpenFile which will let you open any file using the program associated
                                  with it. Thus, you can open that htm file in IE (or firefox or whatever
                                  the user has set as the default browser)
                                  • 14. Re: Simple openFile script
                                    Level 7
                                    Open by itself will only start up an executable file. You can use open
                                    "fileName" with "application" to open a file. The catch is that you have
                                    to know the full path to the app that will open the file.

                                    For .html docs its simple, usually. You can just use:

                                    open "whatever.html" with browserName()

                                    browserName() is a Lingo function that will return the path to the
                                    user's default browser.

                                    If you are relying on an app that you expect the user to have installed,
                                    then the best action is to use buddyAPI to find the app for you. Once
                                    you find the app, you can use its path to open your file.

                                    --
                                    Rob
                                    _______
                                    Rob Dillon
                                    Adobe Community Expert
                                    http://www.ddg-designs.com
                                    412-243-9119

                                    http://www.macromedia.com/software/trial/
                                    • 15. Re: Simple openFile script
                                      jumpOnCommand Level 1
                                      Strangely, I was at the browserName() syntax, but it didn't occur for me to use it. I was trying;

                                      gotoNetPage moviePath&"myPage.html" -- which didn't work.

                                      However when I try;

                                      open moviePath&"subfolder\whatever.html" with browserName()

                                      again, it doesn't like it. How do it point it in the right direction into my subfolder? Otherwise, IE tries to open: " http://dvr400p/index.htm"

                                      Thanks alot
                                      • 16. Re: Simple openFile script
                                        Level 7
                                        jumpOnCommand wrote:
                                        > Strangely, I was at the browserName() syntax, but it didn't occur for
                                        > me to use it. I was trying;
                                        >
                                        > gotoNetPage moviePath&"myPage.html" -- which didn't work.
                                        >
                                        > However when I try;
                                        >
                                        > open moviePath&"subfolder\whatever.html" with browserName()
                                        >
                                        > again, it doesn't like it. How do it point it in the right direction
                                        > into my subfolder? Otherwise, IE tries to open:
                                        > " http://dvr400p/index.htm"

                                        Try
                                        open (quote & "file:///" & the moviePath & "subfolder\whatever.html" &
                                        quote) with browserName()

                                        n.b. the "the" in front of "the moviePath".

                                        The "open" command is not reliable. BrowserName() is not reliable (at least
                                        not on Macs). Judge for yourself whether you'd prefer to use the reliable
                                        baOpenFile() instead...

                                        Andrew


                                        • 17. Re: Simple openFile script
                                          jumpOnCommand Level 1
                                          Thanks Andrew. I tried your method, but to no avail. I thought I saw an error in your script;
                                          was:
                                          open (quote & "file:///" & the moviePath & "DVR400N\software.htm" & quote) with browserName()

                                          my addition changing the quote:
                                          open (quote & "file:///" & quote & the moviePath & "DVR400N\software.htm") with browserName()

                                          However neither worked. I'm slightly reserved about using baOpenFile, unless its quite simple to use? Can someone shed a little light on either the baOpenFile or Andrews script above?

                                          Thanks for everyones help so far :)

                                          jumpOnCommand
                                          • 18. Re: Simple openFile script
                                            Level 7
                                            jumpOnCommand wrote:
                                            > Thanks Andrew. I tried your method, but to no avail.

                                            What's happening/not happening?

                                            > I thought I saw
                                            > an error in your script;
                                            > was:
                                            > open (quote & "file:///" & the moviePath & "DVR400N\software.htm" &
                                            > quote) with browserName()
                                            >
                                            > my addition changing the quote:
                                            > open (quote & "file:///" & quote & the moviePath &
                                            > "DVR400N\software.htm") with browserName()

                                            No, that would be wrong because I was putting double-quotes around the
                                            entire URL (which uses the file:/// pseudo-protocol). The open command
                                            cannot cope with paths/filenames with spaces; it was possible that was
                                            messing it up for you. Also, it can't cope if there are more than 127
                                            characters.

                                            > However neither worked. I'm slightly reserved about using baOpenFile,
                                            > unless its quite simple to use?

                                            It is.

                                            err=baOpenFile(the moviePath & "DVR400N\software.htm", "normal")
                                            if err < 32 then
                                            alert("BuddyAPI error number " & string(err))
                                            end if

                                            So it'll let you know what didn't work. There's a list of what the error
                                            numbers mean in the buddyAPI docs, or I wrote a handler to translate it to
                                            text:-
                                            http://groups.google.com/group/macromedia.director.lingo/browse_frm/thread/f988d68ec44db73 /fc503d6532d5cdb4?lnk=st&q=&rnum=1&hl=en#fc503d6532d5cdb4

                                            Andrew


                                            • 19. Re: Simple openFile script
                                              jumpOnCommand Level 1
                                              So you script is just a query? I would actually need to run a operation to get IE to launch?

                                              I was under the influence buddyAPI is a 3rd party application. If so, does it work closely with director? Being in my early days of Director, I wanted to avoid to much complexity.

                                              I think I'll look into it in the morning.

                                              Thanks alot.

                                              jumpOnCommand
                                              • 20. Re: Simple openFile script
                                                Level 7
                                                BuddyAPI is a plugin for Director (known as an xtra). It works superbly
                                                well with Director, as that is what it is made for. You can download it
                                                for free at www.mods.com.au/budapi. The documentation that it comes
                                                with is very complete and easy to follow, and I advise reading through
                                                it. Anyway, once you install it (by copying it into your
                                                Director/configuration/xtras folder), you can just use the extra lingo
                                                commands that it offers. The one in question here, baOpenFile, will (as
                                                its name implies) open a file. It is a single line of code (and a few
                                                extra lines for error checking).

                                                It is free to use up to 2 functions in any projector. If you want to
                                                use >2 then you need to buy it. It is well worth the money! In this
                                                case, you are only using one command (even if you use it multiple
                                                times), so it would be totally free.