Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Please help!! New to Flash making memory game

New Here ,
May 14, 2013 May 14, 2013

Trying to make this flash memory game and im a complete noob so need help. I need to reset the cards back to 10. i believe the cards is totalchildren = 10 or something but i dont know. Get errors 1119 and 1120.

Scene 1, Layer 'Layer 1', Frame 1, Line 1791120: Access of undefined property reset.
Scene 1, Layer 'Layer 1', Frame 1, Line 1801119: Access of possibly undefined property buttonMode through a reference with static type flash.display:SimpleButton.

import away3d.cameras.*;

import away3d.containers.*;

import away3d.materials.*;

import away3d.primitives.Plane

import away3d.primitives.Cube

import away3d.containers.ObjectContainer3D;

import away3d.core.math.Number3D;

import caurina.transitions.*

import fl.motion.MotionEvent;

var scene:Scene3D;

var camera:Camera3D;

var view:View3D;

var totalchildren:int=10

var cards:Array

var textures:Array = [ new texture0(0,0),

                                                     new texture1(0,0),

                                                     new texture2(0,0),

                                                     new texture3(0,0),

                                                     new texture4(0,0)]

var backtexture:BitmapData = new textureback(0,0)

var woodtexture:BitmapData = new texturewood(0,0)

var cardwidth:Number = 110

var cardheight:Number = 150

var xoffset:Number = 10

var yoffset:Number = 10

var cardsholder:ObjectContainer3D

var selectedCard1:Plane

var selectedCard2:Plane

var disableMouseEvents:Boolean=false

function initAway3D():void {

          scene = new Scene3D();

 

          camera = new Camera3D();

          camera.y = 700

          camera.z = 500

          camera.lookAt(new Number3D(0,0,0))

 

          view = new View3D({scene:scene, camera:camera});

          view.x = stage.stageWidth/2

          view.y = stage.stageHeight/2

          addChild(view);

}

function createGround():void {

          var cube:Cube = new Cube({width:680,depth:400,height:20,pushback:true,ownCanvas:true,material: new BitmapMaterial(woodtexture)})

          cube.y=-20

          scene.addChild(cube)

}

function createCard(texture:BitmapData,id:int):ObjectContainer3D {

          var card:ObjectContainer3D = new ObjectContainer3D()

 

          var front:Plane = new Plane({width:cardwidth,height:cardheight, material: new BitmapMaterial(texture,{smooth:true})})

          var back:Plane = new Plane({width:cardwidth,height:cardheight, material: new BitmapMaterial(backtexture,{smooth:true})})

          front.rotationY=180

          back.rotationZ=180

          back.rotationY=180

 

 

          back.extra = {}

          back.extra.id = id

          back.extra.targetCard = card

          back.addOnMouseDown(onBackClicked)

 

          card.rotationZ=180

          card.addChild(front)

          card.addChild(back)

          card.ownCanvas = true

          return card

}

function initCards():void {

          cards = new Array()

          for(var i:int = 0; i<textures.length; i++ ) {

 

                    var card1:ObjectContainer3D = createCard(textures,i)

                    var card2:ObjectContainer3D = createCard(textures,i)

 

                    cards.push( card1 )

                    cards.push( card2 )

 

          }

}

function randomizeCards():void{

          var newArray:Array = new Array();

          while(cards.length > 0){

                    newArray.push(cards.splice(Math.floor(Math.random()*cards.length), 1)[0]);

          }

          cards = newArray

}

function addCardsToScene():void {

          cardsholder = new ObjectContainer3D()

          var currentindex:int = 0

 

          for(var i:int=0; i<2; i++) {

                    for(var b:int=0; b<5; b++) {

                              cards[currentindex].x=b*(cardwidth+xoffset)+cardwidth/2

                              cards[currentindex].z=i*(cardheight+yoffset)+cardheight/2

                              cardsholder.addChild(cards[currentindex])

                              currentindex++

                    }

          }

 

          var cardswidth:Number = (5*cardwidth) + (4*xoffset)

          var cardsheight:Number = (2*cardheight) + (1*yoffset)

 

          cardsholder.x=-cardswidth/2

          cardsholder.z=-cardsheight/2

 

          scene.addChild(cardsholder)

}

function onBackClicked(e:Event):void {

          if(disableMouseEvents==false) {

                    if(selectedCard1==null) {

                              selectedCard1 = e.currentTarget as Plane

                    }else {

                              if(selectedCard2==null) {

                                        selectedCard2 = e.currentTarget as Plane

                                        waitForDecision()

                                        disableMouseEvents = true

                              }

                    }

                    Tweener.addTween(e.currentTarget.extra.targetCard,{y:50,rotationZ:0,time:1})

          }

}

function waitForDecision():void {

          var timer:Timer = new Timer(1000,1)

          timer.addEventListener(TimerEvent.TIMER,makeDecision)

          timer.start()

}

function makeDecision(e:Event):void {

          if(selectedCard1.extra.id == selectedCard2.extra.id) {

                    Tweener.addTween(selectedCard1.extra.targetCard,{alpha:0,time:0.2,onComplete:removeCard,onCompleteParams:[selectedCard1.extra.targetCard]})

                    Tweener.addTween(selectedCard2.extra.targetCard,{alpha:0,time:0.2,onComplete:removeCard,onCompleteParams:[selectedCard2.extra.targetCard]})

          }else {

                    Tweener.addTween(selectedCard1.extra.targetCard,{y:0,rotationZ:180,time:1})

                    Tweener.addTween(selectedCard2.extra.targetCard,{y:0,rotationZ:180,time:1})

          }

          disableMouseEvents = false

          selectedCard1 = null

          selectedCard2 = null

}

function removeCard(e:ObjectContainer3D):void {

          cardsholder.removeChild(e)

          totalchildren--

          if(totalchildren==0) {

                    trace("WIN")

          }

 

}

function startToRender():void {

          addEventListener(Event.ENTER_FRAME, render);

}

function render( e:Event ):void{

          view.render();

}

initAway3D()

createGround()

initCards()

randomizeCards()

addCardsToScene()

startToRender()

reset_btn.addEventListener(MouseEvent.CLICK, reset);

reset_btn.buttonMode = true;

TOPICS
ActionScript
909
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 14, 2013 May 14, 2013

If you have not defined a function named "reset", you need to.

If the reset_btn object is a button (SimpleButton) it does not have a buttonMode property... it basically is permanently in buttonMode.

Translate
LEGEND ,
May 14, 2013 May 14, 2013

If you have not defined a function named "reset", you need to.

If the reset_btn object is a button (SimpleButton) it does not have a buttonMode property... it basically is permanently in buttonMode.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 14, 2013 May 14, 2013

how do i check its a simple button? forgive my noobiness Flash is my weak point and always has been.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 14, 2013 May 14, 2013
LATEST

If you created it as a button symbol, it is a SimpleButton.  Also, the error is telling you it is.  If you select it on the stage and look at the Properties panel, it should indicate if it is.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines