Dear flash coders,

I've created a class representing playing
cards and it works quite well for me:

 http://preferans.de/flash/Card.as
 http://preferans.de/flash/Card.fla

To reduce the file size (from 300K to 120K),
I don't keep images of complete 32 cards in
the library, but instead I hold the 4 suit images
(spades, hearts, clubs, diamonds) and
4 x 3 pictures (jack, queen and king) there
and then create a card image "on the fly":

        public function set index(n:Number):Void {
                __index = n;

                pic_mc = this.createEmptyMovieClip('pic_mc', 10);

                var depth:Number = 10;
                var rank:Number = CARDS[n].rank;
                var suit:Number = CARDS[n].suit;
                var color:String = suit < DIAMONDS ? 'Black' : 'Red';
                
                var eye:String = (UNKNOWN == rank ||
                    (JACK <= rank && rank <= KING)) ?
                    CARDS[n].label : eye = SUITS[suit];
                for (var key:String in EYE_POS[rank]) {
                        var pos_obj:Object = EYE_POS[rank][key];
                        pic_mc.attachMovie(eye,
                            eye + depth + '_mc', depth++, pos_obj);
                }
               // ...and so on: attach 2 card indices in the corners
         }

Those suits and jack-queen-king images are all
MovieClips in the library, with the following settings:

   Identifier: Hearts
   Class:
   Export for ActionScript [X]
   Export for runtime sharing [_]
   Export in first frame [X]

My problem is that when I'm trying to postpone loading
those MovieClips by unchecking the "Export in 1st frame"
and by setting File->Publish Settings...->Flash->
ActionScript 2.0->Settings...->Export Frame for Classes
to 2 or 10, then my movie stops working: the cards are
empty, no suits and no jack-queen-kings are shown.

Also my preloader TextField only show ups shortly :-(

Does it make any sense to convert the MovieClips
to Graphics in the library? The "Export in 1st frame"
check box is (sometimes???) greyed out then...

Thank you
Alex

PS: Here is the code from my Actions layer (to be
     found in http://preferans.de/flash/Card.fla )

stop();

var depth:Number = 10;

var load_txt:TextField = this.createTextField('load_txt',
        depth++, Stage.width / 2, Stage.height / 2, 300, 100);

onEnterFrame = function() {
        var loaded:Number = getBytesLoaded();
        var total:Number = getBytesTotal();

        load_txt.text = loaded + ' / ' + total;

        if (loaded >= total && loaded > 100) {
                delete onEnterFrame;
        gotoAndPlay('MAIN');
        }
};

//////////////////// And in the frame "MAIN" ///////////

stop();

load_txt._visible = false;

for (var i:Number = 0; i < Card.CARDS.length; i++) {
        var card_mc:MovieClip = this.attachMovie('Card', 'card' + i + '_mc', 
depth++);
        with (card_mc) {
                index = i;
                _x = card_mc._width / 2 +
                    Math.floor(Math.random() * (Stage.width - card_mc._width));
                _y = card_mc._height / 2 +
                    Math.floor(Math.random() * (Stage.height - 
card_mc._height));
                _rotation = Math.floor(Math.random() * 9 - 4);

                addEventListener('clicked', this);
        }
}

function clicked(evt_obj:Object):Void {
        var card_mc:MovieClip = evt_obj.target;
        
        // put the clicked card at the top
        card_mc.swapDepths(depth++);
}
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to