PDA

View Full Version : Some guidance on image placement and Flex vs. Flash


Raconteur
11-27-2009, 04:00 PM
Hi gang,

I have been messing with Flash for many years, but have only done a few appreciable applications with it (usually using more "industrial strength" tools).

I am trying to brush the dust off of my chops, as it were, by writing a game in Flash CS4.

To that end, I have a couple of questions that I am hoping someone would be kind enough to shed some light on.

First, the game is a card game, similar to Magic: The Gathering, where the cards have an image and some description text displayed on them. I have created a symbol (a MovieClip) that is exported in frame 1, let's say as BattleCardGfx.

In the symbol, I have a background, which is just a solid color, then two areas of white (with stroked border) where the image and description will go.

In the description area, I have a dynamic text field setup and named "descText."

In the image area is a symbol (a MovieClip) called "cardImage." The symbol is setup in the proper location and sized correctly - in this case X=0, Y=-31, W=100, H=100.

I am reading the deck from an XML file, and placing the data into an instance of a Card (new BattleCardGfx()), and everything works great, except the image. When I place the image it does not appear to be getting put into the bounds specified by the "cardImage" symbol. Here is the code I am using to do it:


public function addImage(loc:String):void {
var imgLoader:Loader = new Loader();
var img:URLRequest = new URLRequest(loc);
imgLoader.load(img);
basis.cardImage.removeChildAt(0);
basis.cardImage.addChild(imgLoader);
}

I remove the existing image (just a place holder from when I built the symbol) and then add the Loader. I am assuming that since "cardImage" is an instance of the symbol that has all of the parameters of where I want the image to appear, adding a child to that should place it in the proper location, but it is not. The image appears down and to the right of the area by about 100 pixels in each direction.

Can someone tell me what I am missing here?

My other question is that since I am not using the timeline at all, it seems this would be a great candidate to do in Flex3, which I would love to do. Can anyone point me to a tutorial where I can learn how I would do things like add items to the Library so I can do the export to make them available to the rest of the code, like you would in Flash?

Thanks a million!!!

C

Raconteur
11-27-2009, 04:13 PM
Ok... so a bit of digging, and I found that the image is getting place right where it should be. It's just that the point of registration is the upper left corner, not the center, and the upper left corner is placed at 0,0, which is the center (reg point) of the card. I offset it by -50 (1/2 the width of the image) in both directions, and viola!

Now, for the Flex bit... any assistance there would be MUCH appreciated!

C