Flash
  Home arrow Flash arrow Page 5 - Using XML and ActionScript with Flex Appli...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Using XML and ActionScript with Flex Applications
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2008-05-29

    Table of Contents:
  • Using XML and ActionScript with Flex Applications
  • Reading XML Data
  • Writing to and Editing XML Objects
  • Reflection
  • Getting the Class by Name

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using XML and ActionScript with Flex Applications - Getting the Class by Name


    (Page 5 of 5 )

    If you have a class name, you can retrieve a reference to the class using the getDefinitionByName() function. The function requires a string parameter specifying a class name, and it returns an Object type. The function returns an Object type rather than aClasstype because it could also theoretically return a reference to a function if you pass it a fully qualified function name (e.g.,flash.util.getTimer). If you’re certain that you’re retrieving a class reference, you can cast the return value toClass, as in the following example:

      var classReference:Class = Class(getDefinitionByName("flash.net.URLLoader"));

    Once you’ve retrieved a reference to a class, you can create anewinstance, as follows:

      var instance:Object = new classReference();

    Obviously you can use the return value fromgetQualifiedClassName()orgetQualifiedSuperclassName()in conjunction withgetDefinitionByName(), as in the following example:

      var loader:URLLoader = new URLLoader();
      var className:String = getQualifiedClassName(loader);
      var classReference:Class = Class(getDefinitionByName(className));
      var instance:Object = new classReference();

    Class Introspection

    You can use describeType() to return a description of all the events, public properties, and public methods of an object. Simply pass the method a reference to the object you want to introspect. The method returns an XML object that details the class name, superclass, various class settings, implemented interfaces, constructor signature, public method signatures, and public properties descriptions. 

    The following example retrieves the description for aURLLoaderobject:

      var loader:URLLoader = new URLLoader();
      var description:XML = describeType(loader);
      trace(description);

    The preceding example outputs the following:

      <type name="flash.net::URLLoader" base="flash.events::EventDispatcher"
      isDynamic="false" isFinal="false" isStatic="false">
       
    <metadata name="Event">
          <arg key="name" value="httpStatus"/>
          <arg key="type" value="flash.events.HTTPStatusEvent"/>
        </metadata>
       
    <metadata name="Event">
          <arg key="name" value="securityError"/>
          <arg key="type" value="flash.events.SecurityErrorEvent"/>
        </metadata>
       
    <metadata name="Event">
          <arg key="name" value="ioError"/>
          <arg key="type" value="flash.events.IOErrorEvent"/>

        </metadata>
       
    <metadata name="Event">
          <arg key="name" value="progress"/>
          <arg key="type" value="flash.events.ProgressEvent"/>
        </metadata>
       
    <metadata name="Event">
          <arg key="name" value="complete"/>
          <arg key="type" value="flash.events.Event"/>
       
    </metadata>
       
    <metadata name="Event">
          <arg key="name" value="open"/>
          <arg key="type" value="flash.events.Event"/>
       
    </metadata>
        <extendsClass type="flash.events::EventDispatcher"/>
        <extendsClass type="Object"/>
        <implementsInterface type="flash.events::IEventDispatcher"/>
        <constructor>
          <parameter index="1" type="flash.net::URLRequest" optional="true"/>
        </constructor>
        <variable name="bytesTotal" type="uint"/>
        <variable name="data" type="*"/>
        <method name="load" declaredBy="flash.net::URLLoader" returnType="void">
         
    <parameter index="1" type="flash.net::URLRequest" optional="false"/>
        </method>
        <method name="close" declaredBy="flash.net::URLLoader" returnType="void"/>
        <variable name="dataFormat" type="String"/>
        <variable name="bytesLoaded" type="uint"/>
        <method name="dispatchEvent" declaredBy="flash.events::EventDispatcher"
      returnType="Boolean">
         
    <parameter index="1" type="flash.events::Event" optional="false"/>
        </method>
        <method name="toString" declaredBy="flash.events::EventDispatcher"
      returnType="String"/>
       
    <method name="willTrigger" declaredBy="flash.events::EventDispatcher"
      returnType="Boolean">
         
    <parameter index="1" type="String" optional="false"/>
        </method>
        <method name="addEventListener" declaredBy="flash.events::EventDispatcher"
      returnType="void">
          <parameter index="1" type="String" optional="false"/>
          <parameter index="2" type="Function" optional="false"/>
          <parameter index="3" type="Boolean" optional="true"/>
          <parameter index="4" type="int" optional="true"/>
          <parameter index="5" type="Boolean" optional="true"/>
       
    </method>
        <method name="hasEventListener" declaredBy="flash.events::EventDispatcher"
      returnType="Boolean">
         
    <parameter index="1" type="String" optional="false"/>
        </method>
        <method name="removeEventListener" declaredBy="flash.events::EventDispatcher"
      returnType="void">
          <parameter index="1" type="String" optional="false"/>
          <parameter index="2" type="Function" optional="false"/>
          <parameter index="3" type="Boolean" optional="true"/>
       
    </method>
      </type>

    With some work, you can create complex systems that use objects to create sophisticated and dynamic applications.

    Summary

    In this chapter, we discussed the fundamentals of ActionScript 3.0. ActionScript is the ECMAScript-standard-based programming language used by Flex applications. Although the topic of ActionScript is far too complex to discuss comprehensively in one chapter, we have covered many of the basics you’ll need to get started writing ActionScript code, including where to place the code, basic syntax, common data types, how to write classes, the event model, error handling, working with XML, and reflection. 


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Programming Flex 2," published by...
     

    Buy this book now. This article is excerpted from chapter four of the book Programming Flex 2, written by Chafic Kazoun and Joey Lott (O'Reilly, 2007; ISBN: 059652689X). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - Critical Flash Vulnerability Heats Up the Web
    - More on Nonpersistent Client-Side Remote Sha...
    - Nonpersistent Client-Side Remote Shared Obje...
    - Using the Decorator Pattern for a Real Web S...
    - Using Concrete Decorator Classes
    - Delving More Deeply into the Decorator Patte...
    - The Decorator Pattern in Action
    - A Simple Decorator Pattern Example
    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT