# File lib/xml_parser.rb, line 105
  def self.add_event(class_name,event)
    
    event_class = event[1].attributes["Class"]
    event_type = event[1].attributes["Type"]
    method = event.attributes["Name"]

    #-- Adds a method to the Flex object, which is the name of an event in ActionScript
    # The developer can override the default tags, and they are braided in.
    class_name.add_method(shift_case(method)) do
      |*argv|
      options = argv.shift || {}
      
      properties = REXML::Document.new event.to_s
      
      options.each_pair do |key, value|
        properties.elements.each("Event/Property") do |property|
          if(property.attributes["Name"] == shift_case(key.to_s, true))
            property.attributes["DefaultValue"] = value
          end
        end
      end
      
 
      # This part handles synchronization between a Flex object and the framework.
      # The developer needs to add a wait tag to the event.
      # It loops over and tries the object until it gets a hit or that the time
      # runs out.

      if(options[:wait] != nil)
        count = options[:wait]

        new_event = flex_object.addevent(event_type, event_class, @id, properties.to_s)
        while((new_event != nil || new_event == "Not synchronized")&& count > 0)
          sleep(1)
          count = count - 1
          new_event = flex_object.addevent(event_type, event_class, @id, properties.to_s)
        end
      else
        new_event = flex_object.addevent(event_type, event_class, @id, properties.to_s)
        if(new_event == "Not synchronized")
          count = $wait_sync
          while(new_event == "Not synchronized" && count > 0)
            sleep(1)
            count = count -1
            new_event = flex_object.addevent(event_type, event_class, @id, properties.to_s)
          end
        end
      end

      raise new_event unless new_event == nil
      
      is_sync
      
      sleep(funfx.speed) # To make the interacttion slow enough so people can watch
    end
  end