开发者

Have xml load with page that flash will read from?

Here's my problem that I have been trying unsuccessfully to find a solution for. I am building some flash menus that are going to pull from what I was hoping to be an xml file, but the client I am building it for doesn't have the fastest database in the world so when the page loads flash, it still takes a while to load the xml. This is undesirable as the viewer has already waited to load the page and now they're forced to wait for it to load again. I am trying to find a way for the page and the xml to be loaded together for flash to be able to read. I have explored flash vars, but it doesn't look like that was set up to contain an entire xml document as special characters break the html, 开发者_如何学Gowhich is the same reason why I couldn't make it all parameters instead of xml.

Does anyone know a way to get the xml loaded with the page, or another way of getting rss-like information into flash so that flash has it's content immediately?


What's your coding environment? You're referring to your client's database and flash slow loading times, this shouldn't really be related. What data is Flash loading from the database?

One way to get your XML to load as quickly as possible is to use some form of preloader movie. This movie would have two functions:
- 1 Load XML data
- 2 Load MainMovie

This first movie would load very quickly since you could keep the graphic assets to a minimum, namely a simple progress bar/message informing the user that the main swf is loading.

Whilst the main movie is loading , you should have retrieved and parsed the XML data so that you could assign the resulting data to the loaded SWF.

Here's a condensed version:

     //Preloader
     private var menuData:Object;

     public function Preloader()
     {
           loadXMLData();
           loadMainMovie();
     }

     private function loadXMLData():void
     {
         var loader:URLLoader = new URLLoader(); //etc...
     }

     private function xmlLoaded( event:Event ):void
     {
         menuData = parseXMLData( event.target.data );
         //remove listener
     }

     private function loadMovieComplete(event:Event ):void
     {
         var main:MovieClip = event.currentTarget.content as MainClass;

         if( menuData != null )
         {
             main.menuData = menuData;
             addChild( main );

         }else{

            //if your XML takes more time to load than your MainMovie
            //you may have to reconsider your options!
            //in any case you could add a listener here
            //to check when the xml load is complete
         }
         //remove listener
     }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜