PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
unidentified loop over flow
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: unidentified loop over flow

  1. #1
    Member
    Join Date
    May 2010
    Posts
    32

    unidentified loop over flow

    I'm trying to make a card game. I have a card and a deck class. The card class works fine but the deck has a weird loop. Here's my code:
    Actionscript Code:
    public class Deck extends MovieClip
        {
            private var i:int;
           
            private var balls:Array = [1,2,3,4,5,7,8,10,11,12,13,14];
            private var angles:Array = [1,2,3,4,5,7,8,10,11,12,13,14];
            private var crosses:Array = [1,2,3,5,7,10,11,13,14];
            private var carpets:Array = [1,2,3,5,7,10,11,13,14];
            private var stars:Array = [1,2,3,4,5,8];
            private var whots:Array = [20,20,20,20,20];
           
            public var cardsOnDeck:Array = new Array();
           
            public function Deck() {
                var dCounter:int = 0;
               
                for(i=0;i<balls.length;i++){
                    cardsOnDeck[dCounter] = new Card(balls[i],"ball");
                    dCounter++;
                }
                for(i=0;i<angles.length;i++){
                    cardsOnDeck[dCounter] = new Card(angles[i],"angle");
                    dCounter++;
                }
                for(i=0;i<crosses.length;i++){
                    cardsOnDeck[dCounter] = new Card(crosses[i],"cross");
                    dCounter++;
                }
                for(i=0;i<carpets.length;i++){
                    cardsOnDeck[dCounter] = new Card(carpets[i],"carpet");
                    dCounter++;
                }
                for(i=0;i<stars.length;i++){
                    cardsOnDeck[dCounter] = new Card(stars[i],"star");
                    dCounter++;
                }
                for(i=0;i<whots.length;i++){
                    cardsOnDeck[dCounter] = new Card(whots[i],"whot");
                    dCounter++;
                }
               
                initializeCards();
               
                addEventListener(Event.ENTER_FRAME, control);
               
            }
           
            public function control(evt:Event):void {
               
            }
           
            private function initializeCards():void {
                var child:Card;    
                for(i=0;i<cardsOnDeck.length;i++){
                    child = Card(cardsOnDeck[i]);
                    addChild(child);
                }
            }
           
        }

    I tried scraping the initializeCards() method and call the addChild in the constructor (i.e after each definition) but no dice. The method definitely runs well, because in the program I see the last/top card added to the stage... I just think it's somehow still doing something in the loop with the arrays I don't quite understand. Help? Thanks.

  2. #2
    Member
    Join Date
    May 2010
    Posts
    32
    The cards on the deck animate (72 frames of repeats mainly) is that a problem?

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Describe the actual problem.
    What do you think is "weird", and what, if anything, isn't working?

  4. #4
    Member
    Join Date
    May 2010
    Posts
    32
    Oh wow... Amidst all that I can't believe I forgot to spell out the problem. When I run it, flash player slows down dramatically. There is enough time to see the cards added to the stage but after that it just freezes (same manner in which it would if you had an endless loop calling null variables in one frame) and I would have to ctrl+alt+delete.
    I tested by creating one single card before and after the deck. The single card before the deck appears but the one after the deck doesn't appear (I'm guessing the code wasn't reached). Thanks in advance.

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I don't see anything that would cause an infinite loop or particular inefficiency. Does Card do anything expensive?

    Personally, I wouldn't use dCounter, I'd just use the push method to put new cards in cardsOnDeck. But that shouldn't have any bearing on this.

  6. #6
    Member
    Join Date
    May 2010
    Posts
    32
    Thanks for the push advice. I'll start using that instead! As for the Card class... I don't think it does anything too expensive:
    Actionscript Code:
    package
    {
        import flash.display.*;
        import flash.events.Event;
       
        public class Card extends Sprite
        {
            public var value:int;
            public var type:String;
            public var face:Boolean;
            public var cardImage:MovieClip;
           
            public function Card(v:int, t:String) {
                value = v;
                type = t;
                face = true;
                cardImage = new WhotCard();
                cardImage.x = cardImage.width/2;
                cardImage.y = cardImage.height/2;
                addEventListener(Event.ENTER_FRAME, control);
               
                addChild(cardImage);
               
               
                this.width *= 0.8;
                this.height *= 0.8;
                            //just a slight re-adjustment
            }
           
            public function control(evt:Event):void {
                if(face){
                    cardImage.gotoAndStop(type);
                    cardImage.vText.gotoAndStop(value);
                    cardImage.vText.visible = true;
                   
                }
                else{
                    cardImage.gotoAndStop("back");
                    cardImage.vText.visible = false;
                }
            }
            }
    }

    Maybe the control? I made another card game before, I was just trying to improve the graphics, rules and the game in general. I can't imagine I did something much different than this.

    But just in case, here is the main class as well:

    Actionscript Code:
    package
    {
        import flash.display.*;
        import flash.events.*;
        import flash.text.*;
        import flash.utils.Timer;
       
        import org.osmf.events.TimeEvent;
       
        [SWF(frameRate="24", width="700", height="500", backgroundColor="#666666")]
       
        public class WhotReloaded extends Sprite
        {
            protected static var instance:WhotReloaded = null;
           
           
            public function WhotReloaded() {
                addEventListener(Event.ENTER_FRAME, control);
                var card1:Card = new Card(2, "carpet");
                addChild(card1);
               
                var card3:Deck = new Deck();
                card3.x = 350;
                addChild(card3);
               
            }
           
            static public function get Instance():WhotReloaded {
                if ( instance == null ) instance = new WhotReloaded;
                return instance;
            }
           
            public function control(evt:Event):void {
               
            }
        }
    }

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I don't really know how badly that amount of animated movieclips would impact performance, but I would not think it would cause a complete grind-to-halt situation.

    Can you use a performance profiling tool to see what's using the most processor resources?

  8. #8
    Member
    Join Date
    May 2010
    Posts
    32
    Thank you for taking your time out to help me Flax. After a few more tests I noticed this might be a memory problem and not a loop overflow. For example, in the deck I only allow it create the ball types (12 card instances). It runs smoothly then, no lag. I increased to also create the angle types, runs a little slower, and even more so when I add the crosses and so on.

    Never used the profiler before, but with that I noticed a lot of TLF Text processes taking up the most cumulative memory. So I broke all TLF texts apart into graphics and now the entire SWF dropped from 502kb to 9kb and it runs smoothly. Go figure!

    Thanks for your help. Once again I learn something new here.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center