我正在尝试为我的班级制作诸如集中注意力的游戏。我无法获取作为函数输入提供的信息并将它们保存到变量中。这是我正在尝试做的工作版本:工作版本 这是我的卡组件中的代码:
<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>
我的主要 MXML 文件:
<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>
如果需要,然后是我的甲板组件:
<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>