Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:12:02+00:00 2026-06-17T19:12:02+00:00

I am trying to make a game such as concentration for my class. I

  • 0

I am trying to make a game such as concentration for my class. I am having trouble with taking information that is supplied as inputs in a function and saving them to a variable. Here is the working version of what I am trying to do: Working Version
Here is the code from my card component:

<fx:Script>
    <![CDATA[

        private var _frontFile:String;
        private var _backFile:String;



        public function makeCard(suit:String, value:String):void
        {
            _frontFile = "asset/Cards_deck_" + suit + "_" + value + ".jpg";
            _backFile = "asset/Cards_back_Jaguar.jpg";
            var _suit:String = suit;
            var _value:String = value;

        }

        public function turnUp():void
        {
            source = _frontFile;
        }

        public function turnDown():void
        {
            source = _backFile;
        }

        public function turnOver():void
        {
            if (source == _frontFile) {
                source = _backFile;
            }
            else if (source == _backFile) {
                source = _frontFile;
            }
        }


    ]]>
</fx:Script>

</s:Image>

My main MXML file:

<fx:Style>
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace mx "library://ns.adobe.com/flex/mx";
    s|Application {
        backgroundColor: #006600;
    }
    #titleLbl {
        color: white;
        fontSize: 60px;
        paddingTop: 15;
    }
    #infoLbl {
        color: yellow;
        fontSize: 24px;
    }
</fx:Style>

<fx:Script>
    <![CDATA[

        //Gabe Dougherty
        //n222
        //1-24-13

        import cardGames.*;

        private var deck:Deck = new Deck();

        private function init():void
        {
            // Let's exclude the face cards.
            deck.makeDeck(false);

            deck.shuffle();

            // Deal the cards.
            var cardCount:int = deck.numCards();
            for (var i:int = 0; i < cardCount; i++) {

                // Get a card and add it to 'playArea'.
                var c:Card = deck.dealCard();
                playArea.addElement(c);

                // Get the card ready for play.
                c.turnDown();
                c.addEventListener(MouseEvent.CLICK, chooseCard);
            }
        }

        private function chooseCard(e:MouseEvent):void
        {
            var card:Card = Card(e.currentTarget);
            card.turnUp();

            // Report on what type of card.
            infoLbl.text = "The card is the " + card.value + " of " + card.suit;
        }

    ]]>
</fx:Script>

<s:Label id="titleLbl" text="Concentration (sort of)"/>

<s:Label id="infoLbl" text="The card is ..."/>

<s:TileGroup id="playArea" requestedRowCount="4"/>

</s:Application>

And then my deck component if needed:

<fx:Script>
    <![CDATA[

        //set the properties
        private var _suitNames:Array = ['clubs', 'diamond', 'heart', 'spade'];
        private var _valueNames:Array = ['2', '3', '4', '5', '6', '7', '8', '9', '10'];
        private var _faceNames:Array = ['jack', 'queen', 'king', 'ace'];
        private var _cards:Array = new Array;

        //set the methods
        public function dealCard():Card {
            return _cards.pop();
        }

        public function numCards():Number {
            return _cards.length;
        }

        public function shuffle():void {
            for (var i:int = 0; i < _cards.length; i++) {

                // Take the last card from the deck.
                var c:Card = _cards.pop();

                // Insert the card back towards the front of the deck, at a random location.
                var index:int = Math.random() * (i + 1);
                _cards.splice(index, 0, c);
            }
        }

        public function makeDeck(includeFaces:Boolean=true):void {                        
            for each (var suit:String in _suitNames) {

                for each (var value:String in _valueNames) {

                    var card:Card = new Card();
                    card.makeCard(suit, value);
                    _cards.push (card);
                }
            }

                if(includeFaces == true){
                    for each (var suit:String in _suitNames) {

                        for each (var value:String in _faceNames) {

                            var card:Card = new Card();
                            card.makeCard(suit, value);
                            _cards.push (card);
                    }

                }
            }
        }
    ]]>
</fx:Script>
</fx:Object>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:12:03+00:00Added an answer on June 17, 2026 at 7:12 pm

    If you declare a variable inside a function then its scope is local to that function. You can’t use it outside the function–it doesn’t exist.

    So you’ll need to move those declarations for _suit and _value outside of the makeCard function if you want them to be accessible by the rest of the class:

    private var _frontFile:String;
    private var _backFile:String;
    private var _suit:String;
    private var _value:String
    
    public function makeCard(suit:String, value:String):void {
        _frontFile = "asset/Cards_deck_" + suit + "_" + value + ".jpg";
        _backFile = "asset/Cards_back_Jaguar.jpg";
        _suit = suit;
        _value = value;
    
    }
    

    But…
    Since those are private variables, you won’t be able to access them from outside the Card class. You could just make them public variables, but a more flexible way is to add accessor methods to the class. These are public functions that let other classes access the values:

    public function get suit():String {
        return _suit;
    }
    
    public function get value():String {
        return _value;
    }
    

    Now your program should work.

    If you need to be able to change those values from outside the Card class, you’ll need to write public ‘setter’ methods to modify the values of the private variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a game and for the gun class, I need every
I'm trying to make my first game, a console tetris. I have a class
im trying to make a real time strategy game such as starcraft or age
I am trying to make a game that uses collision with face. But i
I am trying to make a game object that can be made semitransparent during
I am trying to make a game that implements high scores into a .txt
I'm currently trying to make a RPG game and I'm running into some trouble.
I trying to make a game where I add a Canvas to a JScrollPane
I am trying to make some game, I'm not going to explain what is
I am just messing around trying to make a game right now, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.