A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Loading files

  1. #1
    Member
    Join Date
    May 2009
    Posts
    62

    Loading files

    I'm been thinking a bit about how I wanna go about doing various file loading into my flash program. Using a zip file seems to be a good way to go for various XML files and/or definition data. However, the only zip library I can find (FZip) doesn't offer simple compression support (if someone has a simple way to add Adler32 checksums that might not be a big problem).

    Also, loading zip files seems to be very slow. Thus, what I'd like to do is load the text data (XML, TXT, etc) from a zip file, and then store the image data in the flash file itself. There doesn't seem to be a way to directly load XML files into flash? Besides hard coding them into the code.

    The problem is this. Far as I can see, the only way to access data loaded into flash is by setting it's AS3.0 name, and referencing that directly. But I want to be able to specify the filename (or some string identifier) of the file, and load based on that. So, I need a way to go from String -> Class.

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    You most certainly can load xml directly into flash , and actually , as3 solved a lot of issue with node referencing by utilizing the e4x convention. So you dont have to say xmlObj.getChildNode(1).childNode.

    Code:
    import flash.net.URLLoader
    import flash.events.Event;
    import flash.net.URLRequest;
    
    private var loader      :     URLLoader;
    private var xmlObj     :     XML;
    
    private function loadXML() : void {
    loader = new URLLoader();
    loader.addEventListener( Event.COMPLETE , onXMLLoadComplete );
    loader.load( new URLRequest( “someXML.xml” ) );
    }
    
    private function onXMLLoadComplete ( evt : Event ) : void {
    xmlObj = new XML( evt.target.data );
    }
    http://livedocs.adobe.com/flash/9.0/...RefV3/XML.html
    Last edited by AttackRabbit; 10-31-2009 at 10:16 AM.

  3. #3
    Member
    Join Date
    May 2009
    Posts
    62
    Sorry, I used the wrong word. I don't want to load the data from an outside source, I want to load embedded data from the flash file itself.

    URLRequest seem to only work with external links.

  4. #4
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    So are you trying to load a list of images from an external data source , and then , load the corresponding image from the library ?When you say "image data" , specifically what process are your referring to ? Are you talking about bitmap data ? Like an array of rastered image data ? Or are you talking about importing an image file , or files , into the library ? If that is the case , i mean that whole process is counter intuitive and bad practice. The whole point of loading external images , is to differ the main load into smaller loads when needed. By having all these emedded bitmaps in your library , your primary load is going to be huge, thus creating bad end user experience.

  5. #5
    Member
    Join Date
    May 2009
    Posts
    62
    I was talking about loading into the library, yeah.

    I agree that it's a bad method, but the way the sites I'm planning on working with work is that you get a 20mb flash file and a 10mb zip file. Also, only one zip file, so you still have to load it all at once. Pretty dumb, but hey.

    So... I'm I stuck using a switch case to sort out the strings into their class counterparts?

  6. #6
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    eek , well I mean if thats the way the way you have to do it I guess you are stuck. Yeah i mean , its not like this thing could even function dynamically anyway , so its not big deal try either use a switch statement , or what i would do is just write a static class , like ImageManager. Have a public method inside of it , that accepts a string as an arguement , and then returns , a new instance of the library symbol. That way you could have your big switch statement away from your main code. So like :
    Code:
    import com.site.managers.ImageManager;
    
    private function getImage() : void {
    
    var myLibImage : MovieClip  = ImageManager.getInstance().getImageByString( "image27" );
    addChild( myLibImage );
    
    }

  7. #7
    Member
    Join Date
    May 2009
    Posts
    62
    Yeah... a bit depressing though

    I'll continue to load from the zip file 'til I use up the 10mb I guess

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