views:

268

answers:

3

OK!! I built a game that grabs a tileSheet (bitmap image) and some xml files from an outside source (not from the library). Turns out that this is a bad idea if I want to post my game on most sites. Cause majority sites only give me ability to load a single file. NOW, I need to figure an alternative.

I tried doing the cross-domain thing but that is a pain cause I am running into some security issues in which I do not know how to get by. I made a seperate post for that issue, with my code in it. But now I need to know if there is some better hope.

It makes sense that maybe I could load a bitmap image from the library. If anyone know's how then please do so share. But What about the xml situation ?? am I pretty much screwed when it comes to that ?? Is it impossible to build a game that reads an xml file and bitmap images from a single file ??

+1  A: 

You want to embed the images and XML file in the SWF.

[Embed(source="../assets/mytiles.bmp")]
var MyTiles:Class;

// When you need the Bitmap:
var myTiles:Bitmap = new MyTiles();

You'll need to use mxmlc, which comes with the Flex SDK.

More info: Embed Almost Anything in Your SWF, Adobe Flex 3 Help: Embedding Asset Types

Edit: Using the Flex SDK with Flash CS4 describes how to set up Flash CS4 so you can use Flex features like the Embed tag. I don't think CS3 has an equivalent feature; you'll need to do the compiling manually or with an external IDE like FlashDevelop in that case.

Selene
I only got flash. Can I not do this with flash ??
numerical25
I've updated my answer with a way to use Embeds with Flash.
Selene
+1  A: 

Are you talking about embedding an image and some XML within your .swf file? This requires mxmlc, I believe.

For an image (AS3):

[Embed(source='image.png')]
private var myImage:Class;
private var ball1:Bitmap = new myImage();

For some XML (AS3):

private var myXML:XML = <rootNode><anotherNode someProp="foo"/></rootNode>
Newtang
Yes, This is what I need!!!! But I only got flash?!?!?! I can not do this with flash ??
numerical25
I have a feeling I am probably going to have to redo this all in flash develop
numerical25
In Flash CS4, the XML bit is fine. It's just Actionscript.For the image, you can add an image to your library, and give it a linkage name. Then you can use: var myImage:Bitmap = new LinkageName();
Newtang
A: 

In your other post I referred to using SWCs You can put your bitmaps and images in the flash file that you export as an swc. and you can create these objects just by calling the class.

Yes, you will have to load all the images you need to use down the road so if you have a game with 50 levels, and most users only need the images used in the first 20, you will need to load all. Although there is a way of going around that, it's quite complicated.

The other nice thing about these SWCs is that you can have 20 of them, each holding different assets and call them when you want. For example I've got a swc library that holds all the components. The flex compiler will push only the contents you need in the final swf, so if you have assets in the SWCs that you're not using, they won't bloat your file needlessly.

You will also find that a lot of libraries are now available in swc format, like the google API.

Daniel