3 Replies Latest reply on Nov 12, 2009 12:16 PM by ImLearningW3D

    Browse button in the getpropertydescriptionlist handler

    ImLearningW3D

      I have a behavior used for opening different director movies, using a simple _movie.go(pMyMovieToJumpTo) command.  I would like to use the property "pMyMovieToJumpTo" to store my filename to open.  Simple enough.  However, I can sometimes have my fat-finger days and mistype filenames. I was wondering if there is a way to add a "Browse" button, shown in attached image, into the getpropertydescriptionlist handler so that when I do add this behavior to a sprite, I can simple click and locate my file to open.  It would then put that file name and path into the string field where I would normally type it in.

       

      It seems like this would be a simple thing but I cannot think of how to do it.  Any help would be much appreciated!

        • 1. Re: Browse button in the getpropertydescriptionlist handler
          ImLearningW3D Level 1

          While looking through your forums, I found this by "Newsgroup_User" at the bottom of the discussion:

           

          http://forums.adobe.com/message/582701#582701

           

          He mentioned being able to place a browse button in the getpropertydescriptionlist handler to do what I would like.  But he did not expand on how.

           

          Thanks for your time guys

          • 2. Re: Browse button in the getpropertydescriptionlist handler
            Sean_Wilson Adobe Community Professional

            You can do this, but you have to cobble your own dialog together and use the #runPropertyDialog handler.

             

            Here is a behavior script that - to a degree - does what I think you want. It relies on FileXtra4, but could be re-written to use Buddy API - or even FileIO if all that's needed is a file-select dialog (without the subsequent "open selected file in associated application")

             

            -- Opens selected file in associated application on mouseUp
            -- Attach to a graphic button sprite
            -- ©Sean Wilson 21/10/2004
            property myFile
            property myFileToOpen
            
            
            on beginSprite me
              -- rebuild file path:
              fDelim = the last char of the moviePath
              lPath  = me.mPathToList(the moviePath)
              myFileToOpen  = ""
              repeat while myFile[1] = #up
                lPath.deleteAt( count(lPath) )
                myFile.deleteAt(1)
              end repeat
              
              repeat with aFolder in lPath
                put aFolder & fDelim after myFileToOpen
              end repeat
              nFolders = count( myFile )
              repeat with f = 1 to nFolders
                if f < nFolders then put myFile[f] & fDelim after myFileToOpen
                else put myFile[f] after myFileToOpen
              end repeat
              
              --  put myFileToOpen
            end
            
            
            on isOKToAttach (me, aType, aNum)
              if ( aType = #graphic ) then return TRUE
            end isOKToAttach
            
            
            on getPropertyDescriptionList
              return [#myFile:[#comment:"File to open on mouseUp:", #format: #string, #default: ""]]
            end
            
            
            on runPropertyDialog me, aList
              if ( (the moviePath) = EMPTY ) then
                -- no way to determine a relative path because the path
                -- to the current movie file hasn't been established
                alert "Please save this movie BEFORE choosing a file to link to" &RETURN& "so that a relative path to the chosen file can be established"
                me.mDetatch()
                exit
              end if
              
              -- does the user have a copy of FileXtra4 installed:
              xl = the xtraList
              id = the itemDelimiter
              the itemDelimiter = "."
              prop = [#fileName, #name][ (value((the environment)[#productVersion].item[1]) < 10) + 1 ]
              the itemDelimiter = id
              bFound = 0
              repeat with x in xl
                if offset("FileXtra4", x[prop])  then
                  bFound = 1
                  exit repeat
                end if
              end repeat
              if not(bFound) then
                -- FileXtra4 not found -> bail out
                alert "This behavior requires FileXtra4" &RETURN& "It can be downloaded from http://www.kblab.net/xtras/"
                me.mDetatch()
                exit
              end if
              
              sFile = xtra("FileXtra4").new().fx_FileOpenDialog(the moviePath, "*.*", "Select a file", 0, 1)
              -- did the user "cancel"?
              if ( sFile = EMPTY ) then
                me.mDetatch()
                exit
              end if
              
              -- resolve the fileName against the moviePath
              -- for run-time relative linking (as opposed to hard-coded paths)
              lFilepath  = me.mPathToList(sFile)
              lMoviepath = me.mPathToList(the moviePath)
              if ( lMoviepath[1] <> lFilepath[1] ) then
                alert "Relative path cannot be established as the movie and the selected file are on different drives"
                me.mDetatch()
                exit
              else
                lMoviepath.deleteAt(1)
                lFilepath.deleteAt(1)
              end if
              
              nFolders = count(lMoviepath)
              if nFolders then
                repeat with f = 1 to nFolders
                  if ( lMoviepath[1] = lFilepath[1] ) then
                    lFilepath.deleteAt(1)
                    lMoviepath.deleteAt(1)
                  end if
                end repeat
              end if
              
              nFolders = count(lMoviepath)
              if nFolders then
                repeat with f = 1 to nFolders
                  lFilepath.addAt(1, #up)
                end repeat
              end if
              
              aList[#myFile] = lFilepath
              return aList
            end runPropertyDialog
            
            
            on mPathToList me, aPath
              tList = []
              id = the itemDelimiter
              the itemDelimiter = the last char of the moviePath
              nItems = aPath.item.count
              repeat with i = 1 to nItems
                tFolder = aPath.item[i]
                -- watch for trailing folder delimiter:
                if (tFolder <> EMPTY) then tList.append(tFolder)
              end repeat
              the itemDelimiter = id
              return tList
            end
            
            
            on mDetatch me
              lScripts = sprite(the currentSpriteNum).scriptList.duplicate()
              lScripts.deleteAt( count(lScripts) )
              sprite(the currentSpriteNum).setScriptList(lScripts)
            end
            
            
            on mouseUp me
              -- check that file still exists:
              fx4   = xtra("FileXtra4").new()
              if fx4.fx_FileExists(myFileToOpen) then
                -- what type of file is it?
                sType  = fx4.fx_FileGetType(myFileToOpen)
                nError = fx4.fx_ErrorNumber()
                if ( nError <> 0 ) then
                  case(nError) of
                    -8:  -- folder
                      
                    -71: -- no type
                      
                  end case
                else
                  -- is file provided actually an application:
                  if ( sType = ".exe" ) OR ( sType starts "APPL" ) then
                    nError = fx4.fx_FileRunApp(myFileToOpen)
                    if ( nError <> 1 ) then
                      alert fx4.fx_ErrorString()
                    end if
                    fx4 = VOID
                    exit
                  end if
                end if
                
                app = fx4.fx_FileGetAppPath(sType)
                if ( app <> EMPTY ) then
                  OK = fx4.fx_FileOpenDocument(myFileToOpen)
                  if not(OK) then
                    alert fx4.fx_ErrorString()
                  end if
                else
                  -- associated application not found
                  alert fx4.fx_ErrorString()
                end if
              else
                alert "File not found:" && myFileToOpen
              end if
              fx4 = VOID
            end
            
            • 3. Re: Browse button in the getpropertydescriptionlist handler
              ImLearningW3D Level 1

              VERY NICE Work Sean.

               

              Except for the line:

              prop = [#fileName, #name][ (value((the environment)[#productVersion].item[1]) < 10) + 1 ]

              under the handler:

              on runPropertyDialog me, aList

              The less than (<) sign should be a greater than (>) sign.  Other than that, PERFECT!!

               

              I bow to your greatness