Skip to main content
Inspiring
August 23, 2011
Question

My adventure in as3 continues

  • August 23, 2011
  • 1 reply
  • 1560 views

Hello everyone

In a former post, I asked for a script to display a certain number of images, let's say 3 out of 10; random and unique numbers.

Now I am asking myself the following question:

In case, we are talking about playing cards, and it happens that all the cards, I mean the 3 cards are aces, or tens or kings,

and in this situation, I want to display a text or make a sound; The part with the sound or the text is easy for me; I have no problem with that.

I know intuitively that I have to make a condition which is the following:

If card1==card2==card3== ace  I am going to beep or write something.

As I said, the beeping part, or the writing, I can manage.

My problem is the if condition and the card1, card2, card3. Where in the world are they ?

Do I have to open the array ?  var imageA:Array = ["1.jpg............................10.jpg];

To tell you the truth, I have no idea how to solve it.

PS

Right now, there is a good movie on THIS channel,  & believe you me I  am making a big sacrifice by trying to stimulate my remaining few neurones.

var imageA:Array = [];

var loader1:Loader=new Loader();

addChild(loader1);

var loader2:Loader=new Loader();

addChild(loader2);

var loader3:Loader=new Loader();

addChild(loader3);
loader2.x=200;

loader3.x=400;

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("jamilou.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
{
myXML = new XML(e.target.data);

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

  imageA.push(new URLRequest(myXML.IMAGE));

}

yourbutton.enabled = true;

}

yourbutton.addEventListener(MouseEvent.CLICK,clickF);

yourbutton.enabled = false;

function clickF(e:MouseEvent):void
{

shuffle(imageA);

  loader1.load(imageA[0]);

  loader2.load(imageA[1]);

  loader3.load(imageA[2]);


}

function shuffle(imageA:Array)
{
  var p:int;
  var t:*;
  var ivar:int;
  for (ivar = imageA.length-1; ivar>=0; ivar--)
  {
   p=Math.floor((ivar+1)*Math.random());
   t = imageA[ivar];
   imageA[ivar] = imageA

;
   imageA

= t;
  }

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 23, 2011

use:

var imageA:Array = [];

var loader1:Loader=new Loader();

addChild(loader1);

var loader2:Loader=new Loader();

addChild(loader2);

var loader3:Loader=new Loader();

addChild(loader3);
loader2.x=200;

loader3.x=400;

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("jamilou.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
{
myXML = new XML(e.target.data);

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

  imageA.push(new URLRequest(myXML.IMAGE));

}

yourbutton.enabled = true;

}

yourbutton.addEventListener(MouseEvent.CLICK,clickF);

yourbutton.enabled = false;

function clickF(e:MouseEvent):void
{

shuffle(imageA);

  loader1.load(imageA[0]);

  loader2.load(imageA[1]);

  loader3.load(imageA[2]);

evaluateCards(imageA[0].url,imageA[1].url,imageA[2].url);

}

function evaluateCards(s1:String,s2:String,s3:String):void{

// code here

}

function shuffle(imageA:Array)
{
  var p:int;
  var t:*;
  var ivar:int;
  for (ivar = imageA.length-1; ivar>=0; ivar--)
  {
   p=Math.floor((ivar+1)*Math.random());
   t = imageA[ivar];
   imageA[ivar] = imageA

;
   imageA

= t;
  }

}

SamsimmsAuthor
Inspiring
August 24, 2011

I tried everything and I don't know what the code is. Going crazy, better make myself a camomile tea.

kglad
Community Expert
Community Expert
August 24, 2011

what are some sample names of your loaded images?