View Full Version : [AS3] Best Way to Load Files in Game From Server?
01-04-2011, 06:06 AM
I was wondering if it was possible to import symbols from a server into my game so that I can essentially keep things like monsters on a server where I can easily update and change. I know there is the URLRequest method but I'm not adept on it's capabilities. Can I use this method or another method to do what I'm looking for (keep monsters, not just images but ideally the whole symbol of the monster, like a hero symbol on a database)? That way I can use the symbol in game and interact with it while it still holds the properties I give it. Thanks guys, any help and direction would be greatly appreciated.
01-04-2011, 09:43 AM
Yup, you can use the Loader class to load swf files, with scripting and everything.
01-04-2011, 04:44 PM
Awesome, thanks for the reply. But does that mean when I export a symbol to .swf it maintains it's layers nested within the symbol that I can access from the main .swf? For instance, I would have a hero with walking animations nested inside of it. Can I still trigger these walk animations from the main .swf? I understand loading .swf files into a main .swf (i've put a game within a .swf) but I haven't quite figured out the interaction between the two, that is, the main .swf manipulating the imported .swf. Sorry, I'm still a beginner if this should be obvious. Thanks again!
01-04-2011, 04:50 PM
When you load a SWF (assuming it is compiled in AS3) you will be able to access it's properties and children just like it was any MovieClip.
Even better, if you give it a custom class and you load it as that class (or an interface that describes that class) you will also be able to access any public methods you may have defined.
01-04-2011, 04:54 PM
Just a bit of friendly advice... Whenever I find myself wondering how something works or if something is possible, I will make a test project to ONLY test out that one thing I'm not sure about.
For you, you might want to export your hero clip and write some simple code to load it and play with it a little. If you write that code well, you can even copy and paste it over to your real project afterward.
01-04-2011, 05:01 PM
Thanks Tom, that generally sums up what I was asking. I'm still a beginner so I actually did try doing a test beforehand. I exported my hero and I tried to call it back into my game instead of detecting it in my timeline. At that point I had no idea what to do. But at least now I know it can be done! :)
01-04-2011, 05:05 PM
In that case you want to try something like this:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onComplete);
hero = loader.content as MovieClip;
* After this you can use that hero variable in any way you like
* just like it was any other MovieClip on the stage.
I didn't test that code though and I may have a typo or something in there. Just play with it yourself.
01-04-2011, 07:04 PM
Thanks a lot. The loader.content as MovieClip I had no idea about lol. Very useful. I think I know what to do from here. Very helpful of you!
01-05-2011, 05:19 PM
Thanks for all the responses. Everything seems to work fine now except I'm not sure what to do when I upload my .swf file to the internet. I submitted online to a website and once on that website the imported .swf doesn't show. Is there a certain command I need to throw in the script or is it because the website hosting the imported .swf file (the hero) has limitations on access?
01-07-2011, 05:04 AM
Once you send it online you might have to look into allowing domains and add the domain to the list in your flash file
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.