jeudi 25 février 2016

AS3 help needed if button1 of a movieclip && button2 of another movieclip clicked then gotoAndPlay

I made a memory cards game which has 24 card images from which the user has to find 7 images in order to win. I am a begginer of actionscript 3 all the code is on frames instead of document or class files. All 24 card images are movieclips, on the set of 7 images i made a button with the second state in the same layer with the win image. All the cards are created dynamically from the library and not in the stage. My problem is what i ever have tried untill now for the last code in order to win had no success i'm very desperate please help me .....I cannot make two movieclips to communicate via variables.

enter image description here

Main timeline frame 6 has this code

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.*;
import flash.ui.Mouse;
import flash.utils.Timer;
import flash.utils.getTimer;
import flash.text.*;
import flash.display.Stage;

var objImage1:logo1 = new logo1;
var objImage2:pic2 = new pic2;
var objImage3:pic3 = new pic3;
var objImage4:logo2 = new logo2;
var objImage5:pic5  = new pic5;
var objImage6:pic6 = new pic6;
var objImage7:pic7 = new pic7;
var objImage8:logo3 = new logo3;
var objImage9:pic9 = new pic9;
var objImage10:pic10 = new pic10;
var objImage11:logo4 = new logo4;
var objImage12:pic12 = new pic12;
var objImage13:pic13 = new pic13;
var objImage14:pic14 = new pic14;
var objImage15:pic15 = new pic15;
var objImage16:logo5 = new logo5;
var objImage17:pic17 = new pic17;
var objImage18:logo6 = new logo6;
var objImage19:pic19 = new pic19;
var objImage20:pic20 = new pic20;
var objImage21:logo7 = new logo7;
var objImage22:pic22 = new pic22;
var objImage23:pic23 = new pic23;
var objImage24:pic24 = new pic24;
var sourceDeck:Array =[objImage1,objImage2,objImage3,objImage4,objImage5,objImage6,objImage7,objImage8,objImage9,objImage10,objImage11,objImage12,objImage13,objImage14,objImage15,objImage16,objImage17,objImage18,objImage19,objImage20,objImage21,objImage22,objImage23,objImage24];
var shuffledDeck:Array = new Array ();
var xValues:Array =["121","321","521","731","937","1136","120","320","520","732","938","1138","120","321","520","730","938","1135","121","322","520","732","938","1135"];
var yValues:Array =["173","173","173","173","173","173","346","346","346","346","346","346","534","534","534","534","534","534","716","716","716","716","716","716"];

function placeCards():void
{
for (var i:int = 0; i<sourceDeck.length; ++i)
{
    addChild(sourceDeck[i]);
    sourceDeck[i].x = int(xValues[i])+20;
    sourceDeck[i].y = int(yValues[i]);  
}
}
placeCards();
function removeCards():void
{
for (var i:int=0;  i<sourceDeck.length; ++i)

{
    removeChild(sourceDeck[i]);

}
}
    function shuffleCards():void
{
while(sourceDeck.length >0)
{
    var r:int=Math.floor(Math.random()*sourceDeck.length);
    shuffledDeck.push(sourceDeck[r]);
    sourceDeck.splice(r,1);
}
}
function placeShuffledCards():void
{
for (var i:int=0; i<shuffledDeck.length; ++i)
{
    addChild(shuffledDeck[i]);
    shuffledDeck[i].x = int(xValues[i]);
    shuffledDeck[i].y = int(yValues[i]);

}
}


function showShuffledCards():void

{   
removeCards();
shuffleCards();
placeShuffledCards();

}
showShuffledCards();
foo();

function foo():void {
    var x:int = 2; // you can use variables as you would normally

    // do something here

    var timer:Timer = new Timer(5000);
    var afterWaiting:Function = function(event:TimerEvent):void {
   timer.removeEventListener(TimerEvent.TIMER, afterWaiting);
   timer = null;
   // 5 seconds have passed, now do something more


   objImage1.gotoAndPlay(10);
   objImage2.gotoAndPlay(10);
   objImage3.gotoAndPlay(10);
   objImage4.gotoAndPlay(10);
   objImage5.gotoAndPlay(10);
   objImage6.gotoAndPlay(10);
   objImage7.gotoAndPlay(10);
   objImage8.gotoAndPlay(10);
   objImage9.gotoAndPlay(10);
   objImage10.gotoAndPlay(10);
   objImage11.gotoAndPlay(10);
   objImage12.gotoAndPlay(10);
   objImage13.gotoAndPlay(10);
   objImage14.gotoAndPlay(10);
   objImage15.gotoAndPlay(10);
   objImage16.gotoAndPlay(10);
   objImage17.gotoAndPlay(10);
   objImage18.gotoAndPlay(10);
   objImage19.gotoAndPlay(10);
   objImage20.gotoAndPlay(10);
   objImage21.gotoAndPlay(10);
   objImage22.gotoAndPlay(10);
   objImage23.gotoAndPlay(10);
   objImage24.gotoAndPlay(10);
   // the scope is retained and you can still refer to the variables you
   // used earlier
   x += 2;
 }
 timer.addEventListener(TimerEvent.TIMER, afterWaiting);
    timer.start();

}

on each one of the seven buttons that each one is inside a movie clip I have this code:

import flash.display.Sprite; 
import flash.text.*;
import flash.display.MovieClip;
import flash.events.MouseEvent;
var success:Boolean = false;
var butpic1:SimpleButton;
butpic1.enabled = true;
addChild(butpic1);

butpic1.addEventListener(MouseEvent.CLICK, clickpics);

function clickpics(event:MouseEvent):void {
gotoAndPlay(1);
var myTextBox:TextField = new TextField();    
    myTextBox.text = "Σωστό Συνέχισε!";  
myTextBox.border = true;    
    myTextBox.borderColor = 0x000000; 
myTextBox.width = 180;    
myTextBox.height = 87;    
myTextBox.x = -77;    
myTextBox.y = -126; 
var myFormat:TextFormat = new TextFormat(); 
myFormat.color = 000000;    
    myFormat.size = 24;
myFormat.align = TextFormatAlign.CENTER
myTextBox.background = true;    
myTextBox.backgroundColor = 0xFFF000;
myTextBox.setTextFormat(myFormat);
    addChild(myTextBox);  

/*var Success=true;*/
//MovieClip(parent).Success2();
//trace(event.target.name);
var success=true;
if(MovieClip(root).butpic3 && butpic1 == success)
    {

    MovieClip(root).gotoAndPlay("win");
    } 
//checking();
//trace(event.target);
//MovieClip(this.parent).success2();
//checking();
//MovieClip(root).check();
//trace("click: " + event.currentTarget.name);
}
//trace(MovieClip(root).but.butpic2);
/*function checking():void
{
if(butpic1 && MovieClip(root).butt.butpic3)
    {
    MovieClip(parent).gotoAndPlay("win");
    } else {
MovieClip(parent).gotoAndPlay("win");
}
}*/

/*function checking():void
{
if(MovieClip(root).Symbol1 && MovieClip(root).button2)
    {

    MovieClip(parent).gotoAndPlay("win");
    } 
}*/

Aucun commentaire:

Enregistrer un commentaire