Applescript - declaring and passing non-existent objects

Discussion in 'Mac Programming' started by Jester831, Dec 3, 2009.

  1. Jester831 macrumors newbie

    Joined:
    Aug 16, 2008
    #1
    I am working to make a script to interact with flash and in doing so I am forced to deal with non-existent objects. That is, at any point in time the object may or may not exist. I started out by writing a very rough conceptual program to make sure I could successfully timeout until objects exist and then click on them and through some effort I got that to work. However, I want modularity in the program and need to find a way to pass non-existent objects into a function that waits for the object to exist.

    An example of what I mean -

    This is the code that works:
    This is the code that does not work - I get the error that the passed object does not exist
    Code:
    on LoadObject(targetObject, targetName, loadThreshold)
    	set loadTime to 0
    	log_event("Loading " & targetName & "... " & loadTime)
    	repeat with loadTime from 0 to loadThreshold
    		try
    			if targetObject exists then
    				log_event("Loaded " & targetName)
    				return true
    			else
    				delay 1
    				log_event("Loading " & targetName & "... " & loadTime)
    			end if
    		end try
    	end repeat
    	log_event("Failed to load " & targetName)
    	return false
    end LoadObject
    Furthermore, in this code, I get the error that the object does not exist and cannot pass it
    Any tips would be much appreciated!
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Maybe in the first chunk of code you should put a try/end try there as well, so that you're not sending a bad object to the function. Also "missing value" is AppleScript's way of testing for null so you could try that too.
     
  3. Jester831 thread starter macrumors newbie

    Joined:
    Aug 16, 2008
    #3
    well, doing a try block somewhat defeats the purpose - if the object exists, there's no point in waiting for it to exist. I want to send a bad object with the expectation that it will become a good object and return true within a timeframe or return false.
     

Share This Page