AFComponents.com

Using Events to display IMG Loop data
Updated: May 7, 2007   Views: 2547  
Description: In this tutorial we are going to use events to accessing component's events. As an example we are going to build a simple application that outputs IMG Loop image descriptions in a text box.
Alright, so what are events? Here is the description of Flash EventDispatcher class that is used by the IMG Loop component.

Events let your application know when the user has interacted with a component, and when important changes have occurred in the appearance or life cycle of a component--such as its creation, destruction, or resizing.

The methods of the EventDispatcher class let you add and remove event listeners so that your code can react to events appropriately. For example, you use the
EventDispatcher.addEventListener()
method to register a listener with a component instance. The listener is invoked when a component's event is triggered.

To see the list of events available in the IMG Loop component check out the component's documentation page http://www.afcomponents.com/components/img_loop/docs/

The event that we are going to use for this tutorial is mouseClick - it will let us know when the loop is clicked. Once we know that information we can grab the image description and display it in a text field.
  1. Create a new document in Flash 8. If you are using Flash 9 be sure to select ActionScript 2.0 document.
  2. Open components window (Window > Components) drag IMG Loop on to the stage.
  3. Select component instance of stage and give it myLoop instance name.
  4. With IMG Loop component selected open component inspector (Window > Component Inspector) and enter path to a sample Flickr feed in the contentRSS property:
    http://api.flickr.com/services/feeds/photos_public.gne?format=rss_200
  5. Now create a dynamic Text Field and give it an instance name myText

  6. We are done with the first part, now let's write some code!

  7. Select the first frame and add the following code:

  8. //Create event listener object
    var eventListener = new Object();

    //Create a function that will be triggered once the component is clicked
    eventListener.handleMouseClick = function (evnt){
      myText.text = evnt.description;
    }
    //Assign event listener to the IMG Loop Component
    myLoop.addEventListener("mouseClick", eventListener.handleMouseClick);


  9. Publish and test your movie!
Your end result should look something like this:


© 2005-2007 advanced flash components