FAQs about common tasks (XML galleries, etc)
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: FAQs about common tasks (XML galleries, etc)

  1. #1
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801

    FAQs about common tasks (XML galleries, etc)

    Some tasks seem to generate a lot of questions on the forum. Rather than answer the same questions over and over, we have made this thread to collect links to resources to help cover these common subjects.
    As always, please feel free to search the forums. Many times, someone else has already provided a solution to the question you were about to ask.

    First up: XML galleries. The following threads and tutorials should cover most of the questions you have on how to set these up and get them working.
    http://board.flashkit.com/board/show...ge+gallery+xml
    http://board.flashkit.com/board/show...=xml+slideshow
    http://board.flashkit.com/board/show...ge+gallery+xml

    http://flashscript.biz/flashas3/xml_...slideshow.html

    http://cosmodro.me/blog/2009/jul/3/b...eshow-framewo/
    Share on Google+

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    In addition to what 5tons has already supplied , here is some supplemental information , compiled from a bunch of posts I have personally answered on these topics. This is by no means and end all be all , comprehensive document on the matter.

    Creating XML Slideshows , Image Galleries , etc.

    This is a pretty tough topic to cover since it can incorporate just about every element of O.O.P design and implementation. Assuming you have a fair understanding of both here are some basics :

    Create Your Data

    While there are no absolute ways in which to do this ,and assuming you have chosen an external XML file as your data source , there are a few basic rules to follow.

    the very first line of your xml should be :

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    Note you may alter the params listed within the node. For example , utf encoding can sometimes cause rendering problems in some browsers. You do not need , or really want , to close the xml tag.

    Below is some sample xml , that would proceed the xml declaration node above. You data does not have to follow this exact format , and you can feel free to nest elements , etc , in whatever architecture makes sense to you. I will not being getting into DTD's and XML Schemas here , but feel free to read up on them. They are essentially rule sets that you include with your xml.

    Code:
    <audio>
         <track title="SOME TITLE">
              <src>audio/somesong.mp3</src>
              <img><![CDATA[image/someimage.jpg]]></img>
    <description></description>
         </track>
         <track title="SOME TITLE">
              <src>audio/somesong.mp3</src>
              <img>image/someimage.jpg</img>
         </track>
         <track title="SOME TITLE">                        
              <src>audio/somesong.mp3</src>
              <img>image/someimage.jpg</img>
         </track>
         <track title="SOME TITLE">
              <src>audio/somesong.mp3</src>
              <img>image/someimage.jpg</img>
         </track>
    </audio>
    This XML could be for an audio image gallery, where a list of cd covers are displayed and when click launch the appropriate audio file.

    Notice that the song title is contained within the track node declaration , and not within the node itself. This i called an attribute. Attributes are great for simple things like titles , paths even. You could very easily move the 'src' value , and declare it as an attribute.

    Code:
    <track title="SOME TITLE" src="audio/songs/somesong.mp3">
    Note do not use special characters or symbols within an attribute value. Instead create a child as show above , and for an extra measure of security , place the info , into a CDATA tag , or character data tag.
    Code:
    <description><![CDATA[WOW SUPER AWESOME COOL !!! @&@#@* '''""<font color='#FFF00'>]]></description>
    Just about anything inside those CDATA tags will be valid.

    Load Your Data


    Now a lot of this will vary depending on what IDE , or development environment you are using , and , how you have architected your project. If you are doing this in the Flash IDE , on frames , you might be in a for a bumpy ride. Scope can very easy get lost , as well , you might run into some order of operations problems. I strongly recommend you break free from that development style , and at least try to encapsulate this stuff in some classes. Ill assume you have decided to handle your application in at least a document level class.

    You will first want to import a few things :

    Code:
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    These are all object types you will use to load your XML , and without them , the compiler will throw a fit.

    You will also want to declare a loader object and an XML object to cache off your data.
    Code:
    private var dataLoader : URLLoader;
    private var someData : XML
    Now there are loads of other events and listeners you can register for , but the COMPLETE listener is most crucial , so create your loader , and a new URLRequest ,

    Code:
    dataLoader = new URLLoader( new URLRequest( "xml/stuff/myXML.xml") );
    dataLoader.addEventListener( Event.COMPLETE , onDataLoadComplete );

    Now youll need to an event handler for COMPLETE
    Code:
    private function onDataLoadComplete( evt : Event ) : void {
    dataLoader.removeEventListener( Event.COMPLETE , onDataLoadComplete );
    someData = evt.target.data;
    };
    Parse and Prep your Data

    In as3 , the nice people at adobe have made it easy on us because we can now parse through and access our XML using E4X. So if we were to have loaded the xml example above , we could say

    Code:
    var trackList : XMLList = XMLList( someData.audio.track );
    That will fill our trackList with all of the track nodes. We no longer have to muck around with childIndex , childNode , etc.

    If you need to access a specific element of the XMLList , you could simply say

    Code:
    var sourcePath :String = String( trackList[ 0 ].src );
    var someTitle : String = String( trackList[ 1 ].@title;
    Build an Interface to use your data

    This Ill leave up to you. I usually create an instance of my data driven component , and pass its data into the contructor as an argument.

    Code:
    private var uiGallery : UIGallery; 
    
    uiGallery = new UIGallery( myXMLListData );
    Then inside my gallery I usually have some sort of addItems() method , that will recursively loop through the XMLList , and items of type whatever , inside a sprite.The idea is this :

    APPLICATION --> Loads XML --> Creates Instance of Component Or Manager --> Creates Instance Of Items --> Items become enabled.
    Share on Google+

  3. #3
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448

    Embedding fonts using external movies

    Loading fonts using external movies and embedding textfields. Example can be found here:
    http://board.flashkit.com/board/showthread.php?t=810994
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center

Poll by Flashkit.com