Hehe, that's a lot of questions, but I'll try to answer as many as i can.

When porting a game to Flex for the purposes you mention, I'd
recommend that you create a 'modular' extension of UIComponents. For
example, for your main game, extend the main game view's class with
UIComponent. If you have, say, a scoreView, then do the same with
what. Don't extend *everything* with UIComponent, you will see a
significant performance problem. I'd recommend that you think of your
game in terms of at-most 4-5 UIComponents.

I'd also recommend that you do not extend your game views with mxml.
MXML has no purpose in this instance, it is more useful when you are
creating a final view.

If you have a tabNavigator and you want to get the parent's width, I
believe that the UIComponent.parent property will work as intended. I
would suggest tho that before you go down that road, that you think
about your Flex development from a Flex perspective. Check this out:

http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_advanced_2.html

The flex display hierarchy is made in such a way that you should
probably not be looking at your paren't width/height to figure out the
size of your component. Use the updateDisplayList() function to
determine the size of your component, and lay it out as expected. As
an aside, attempt to use the 'invalidation' methodology prevalent in
Flex, as it will make your life easier. For example, say your game
requires a value object that represents the model of the game. You
need to pass that to your view, which will then draw it. You could
write something like this:

public function initializeGame(gameData:GameData)
{
      //...initialize game....
}

This is not a very flex way of doing it. The reason being that you'll
probably want to use data binding and states to pass data around. The
more flex way of doing it would be


private var _gameInvalidated:Boolean=false;
private var _gameData:GameData;
[Bindable]
public function get gameData():GameData
{
     return _gameData;
}

public function set gameData(newVal:GameData):void
{
    _gameData = newVal;
    _gameInvalidated = true;
    invalidateProperties();
}

override protected function commitProperties():void
{
   super.commitProperties();
   if(_gameInvalidated){
   ///.....initialize game ....
    _gameInvalidated = true;
    ///perhaps invalidate your display list also...
    }

}

This works better with Flex's component life cycle. The more you know
about this life cycle, the better your life will be. An invaluable
resource for this is to check out the Flex source from SVN and read it
all the time.

As a fun example, let's just say we wanted to make World of Warcraft
as a Flex app. :) The main game viewport would be one UIComponent,
made up of, say, an Away3D engine and flash primitives. The minimap in
the corner would be another component. All the popup windows would be
their own components, with tab controls,etc. And each one would use
Flex's LayoutManager to dynamically place the objects upon screen
resize, etc. The key to making this design work is to harness flex for
what its good at: layout/ui controls, and flash for what its good at:
animation, effects. cool games.

Sorry this turned out to be so long. Looks like my girlfriend is out
of the shower, g2g! :D
C

On Sat, Mar 20, 2010 at 8:33 AM, Alexander Farber
<alexander.far...@gmail.com> wrote:
> Hello,
>
> I'd like to port a game of mine to a Flex app,
> because I'd like to use tabs, controls and charts.
>
> I'm reading the docs for already a week,
> there are lots of them and well explained.
>
> But what do I do with my Sprites?
> My app consists mostly of Sprites,
> for example user avatars with names+ score,
> playing cards and a playing table holding 32 cards.
>
> Should I create a custom components as separate
> .mxml files for them? Should I change "extends Sprite"
> to "extends UIComponent" in my classes?
> Or should I somehow use rawChildren (of the container?)
>
> I' mostly confused by: if you create a custom .mxml
> control, how do you draw stuff inside it, how do you
> maintain the children Sprites of it?
>
> And how can you get the dimensions of the parent.
> For example if I use TabNavigator with Canvas's
> which have width=100% height=100% and put
> my playing cards into a Canvas, how could I find
> its real width x height please?
>
> Regards
> Alex
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to