Memory game random function

Hello,
I made a memory game with a tutorial. My knowledge of AS3 is not that good so I have to following question.
There is a function like Math.Random to random generate number and put them on stage. I made a memory game and the cards are on the same place every time I play the "movie".
I want them to shuffle every time I restart the game. How can I write a good random function in AS3?
Thank you.
Joep van Dongen

So you still cant open my files?
I can post code:
Fla file = Memory.fla
DocumentClass = MemoryGame
This is MemoryGame.as :
package
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import Card;
    import Computer;
    import Muis;
    import Radio;
    import Iphone;
    import Beamer;
    import Platenspeler;
    public class MemoryGame extends MovieClip
        private var _card:Card;
        private var _computer:Computer;
        private var _muis:Muis;
        private var _radio:Radio;
        private var _iphone:Iphone;
        private var _beamer:Beamer;
        private var _platenspeler:Platenspeler;
        private var _cardX:Number;
        private var _cardY:Number;
        private var _firstCard:*;
        private var _totalMatches:Number;
        private var _currentMatches:Number;
        public function MemoryGame()
            _totalMatches = 6;
            _currentMatches = 0;
            createCards();
        private function createCards():void
            _cardX = 45;
            _cardY = 31;
            for(var i:Number = 0; i < 2; i++)
            _card = new Card();
            addChild(_card);
            _computer = new Computer();
            _card.setType(_computer);
            _card.x = _cardX;
            _card.y = _cardY;
            _cardX += _card.width + 50;
            _card.addEventListener(MouseEvent.CLICK, checkCards);
            for(var j:Number = 0; j < 2; j++)
            _card = new Card();
            addChild(_card);
            _muis = new Muis();
            _card.setType(_muis);
            _card.x = _cardX;
            _card.y = _cardY;
            _cardX += _card.width + 50;
            _card.addEventListener(MouseEvent.CLICK, checkCards);
            _cardX = 45;
            _cardY += _card.height + 50;
            for(var k:Number = 0; k < 2; k++)
            _card = new Card();
            addChild(_card);
            _radio = new Radio();
            _card.setType(_radio);
            _card.x = _cardX;
            _card.y = _cardY;
            _cardX += _card.width + 50;
            _card.addEventListener(MouseEvent.CLICK, checkCards);
            for(var l:Number = 0; l < 2; l++)
            _card = new Card();
            addChild(_card);
            _iphone = new Iphone();
            _card.setType(_iphone);
            _card.x = _cardX;
            _card.y = _cardY;
            _cardX += _card.width + 50;
            _card.addEventListener(MouseEvent.CLICK, checkCards);
            _cardX = 45;
            _cardY += _card.height + 50;
            for(var m:Number = 0; m < 2; m++)
                _card = new Card();
                addChild(_card);
                _beamer = new Beamer();
                _card.setType(_beamer);
                _card.x = _cardX;
                _card.y = _cardY;
                _cardX += _card.width + 50;
                _card.addEventListener(MouseEvent.CLICK, checkCards);
            for(var n:Number = 0; n < 2; n++)
                _card = new Card();
                addChild(_card);
                _platenspeler = new Platenspeler();
                _card.setType(_platenspeler);
                _card.x = _cardX;
                _card.y = _cardY;
                _cardX += _card.width + 50;
                _card.addEventListener(MouseEvent.CLICK, checkCards);
        private function checkCards(event:MouseEvent):void
            event.currentTarget.removeEventListener(MouseEvent.CLICK, checkCards);
            if(_firstCard == undefined)
                _firstCard = event.currentTarget;
            else if(String(_firstCard._type) == String(event.currentTarget._type))
                _firstCard = undefined;
                _currentMatches ++;
                if(_currentMatches >= _totalMatches)
            else
                _firstCard.gotoAndPlay("flipBack");
                event.currentTarget.gotoAndPlay("flipBack");
                _firstCard.addEventListener(MouseEvent.CLICK, checkCards);
                event.currentTarget.addEventListener(MouseEvent.CLICK, checkCards);
                _firstCard = undefined;
This is the Card.as:
package
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    public class Card extends MovieClip
        public var _type:*;
        public function Card()
            this.buttonMode = true;
            this.addEventListener(MouseEvent.CLICK, onClick);
        private function onClick(event:MouseEvent):void
            if(this.currentFrame == 1)
            this.play();
        public function setType(type:*):void
            _type = type;
            loader_mc.addChild(_type);
This is the how its put on screen:
So you can see its quiet easy to do this memory game ;-)
I'm really desperate right now because I was really happy how far I got with this game:-)
But now I know my AS3 isnt that good at all.

Similar Messages

  • Is it possible to pass the score of the memory game as a variable using javascript?

    Hi,
    I would like to create a score table for the memory game. For that I need captivate to pass the last sore to a form/page. In the memory game widget there is a variable displayed: memGame_var. Is this really the memory game score, and do you think that I can achieve my goal using javascript?
    thank you!
    Heloisa

    Beware: you have to create a variable, it is not automatically created. And you don't have to use the same name, but in this case for some reason it is not possible to use capitals in the variable name.
    Contrary to some other games, this variable will retain the score indeed.
    Lilybiri

  • Captivate 7 Memory Game Failure

    I am using Captivate 7.  Everything in my presentation is working fine except for the Memory Game interaction.  I've created the slide for the Memory Game and it works perfectly when I preview it in Captivate.  However, when I publish, that particular slide is blank (Memory Game only).  Everything else on the slide is OK.  What is happening so that the Memory Game does not show up?

    Have you set up the publish folder location as a trusted location in Flash Global Security settings?
    http://www.infosemantics.com.au/adobe-captivate-troubleshooting/how-to-set-up-flash-global -security
    Have you tried uploading your content to a web server and testing from there?
    If you want 300 more troubleshooting tips for Cp, you'll need to read the book:
    http://www.infosemantics.com.au/troubleshoot-adobe-captivate

  • Can Flash CS5.5 create ios app with in game purchase function?

    Can I use flash CS5.5 to create ios app with in game purchase function and other ios specific functions? Is there any limitation compare to using ios native development environment? Same questions for Android OS.
    Thank you very much.

    First disable autoplay. It gave errors for me. Try to make the movie play with the play() command.
    to embed the movie in your air bundle, just go to publish settings for your flash project. Then in that screen go to the player settings.
    In the first GENERAL tab you'll see a the bottom that you can add files to your project
    Propably there is allready your .swf and an .xml file in there.
    Using the + icon you can add your video.
    Make sure that your video is in the same directory as your . FLA file and you can use it as is (by name)
    If for example your flashfile is in c:\mytest\mytest.fla and the video in c:\mytest\videos\myvideo.flv , then you will have to load your video as "videos/myvideo.flv" with a FORWARD slash, never use \
    Good luck

  • Query regarding random function

    I am doing a random function this is what i hv done
    static Random svcRand;
    a=svcRand.nextInt();
    its working perfectly but every time a random number is generated its a huge number......How can I keep it within a limit say between 1 and 100 always

    showstopper wrote:
    I am doing a random function this is what i hv done
    static Random svcRand;
    a=svcRand.nextInt(); This code would generate a NullPointerException, but I guess you initialize this somewhere.
    >
    its working perfectly but every time a random number is generated its a huge number......How can I keep it within a limit say between 1 and 100 alwaysThere are two ways
    1. Easy: a = svcRand.nextInt(100) + 1; // number between 1 and 100
    2. More general:
    double start = ...;
    double span = ...;
    double val = svcRand.nextDouble() * span + start;

  • Simple Memory Game

    Hi
    I want to make a really simple Flash memory game. There is no
    need for score, level, time limit or stuff like that. Just a simple
    memory game with 16 cards what you turn and look for a match. Any
    one who know a good tutorial with fla source code?
    I have looked at this tutorial but i can't get this thing to
    work
    http://www.bleacheatingfreaks.com/science/memory/
    Any help to get me started is appreciated

    I've got a Flash memory version here: www.blurredgames.com
    If you like I'll send you the FLA file, but I have no
    tutorial for it... I
    have a Director based tutorial in my last Director book, but
    that's Lingo.
    If you'd like the .fla file let me know and I'll send it
    over. At the very
    least you could simply modify the assets and use it...
    there's even a timer
    and a high-score table...
    Dave -
    Head Developer
    www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • "Enhanced" random function

    I have a slideshow with 25 pics using random(25) function.
    How can I randomize the order so that one image won't be shown
    again until all the images are shown once?

    Create a list of the cast member names. Use the random
    function to pick a number between 1 and the number of items in the
    list. Use that cast member, and delete the name from the list.
    Repeat until there's nothing left in the list.

  • Memory Game Widget

    I'm creating a memory game to help our leanrers prepare for their written driver's test.  Ideally I would like to see them match the road signs with the correct words (I've made PNG files to house the text for each card), but from what I can see we only have the option to match exact pictures.  Is there a way to set it up so that you can have a group of pictures to match againts their counterparts, which would be a different picture?
    I could use the drag/drop tool to achieve something similar in concept of matching, but I like the idea of having a memory game for the added fun. 

    Hi Lilybiri - thanks for the welcome!
    Actually, I was trying to use the new widget in the Captivate 7.  It is something like this one, but I want to match 2 different pictures technically.  For example:  Picture 1: street sign of railway crossing ahead ---- MATCH TO ---- Picture 2: (image of) text says "Railway Crossing Ahead".  That way they have to match a picture to the correct text.  Does that make more sense?  I'm hoping that I can still use the widget, but with more customizable options.
    Wanda

  • Distribution Type in Numbers generated by Random function

    Hello,
    I am using the built-in Random() function in TestStand for generating random numbers with seed value of 0.
    I was wondering about it's distribution. Does the built-in function use Normal or Uniform distribution?
    Thanks

    Uniform.

  • Memory Game Success/Failure Caption Duration

    Is there any way to extend the amount of time the success and failure captions stay on the screen for the memory game in Captivate 7?

    Memory game can fail because of time out as well. Since the variable assigned to memory game does not show up in the variables list, I don't think you can delay it for failure condition.
    For success condition, delete the default captions, add your own caption, name it as say, Success, assign the following advanced action for On Success.
    Show Success.
    Assign cpCmndGotoFrame with CpInfoCurrentFrame
    Sreekanth

  • Memory Game interaction

    Hello,
    I am not quite understanding how to make the memory game work.  I can only get 9 boxes to show up, when I need 18.  And I can't seem to figure out how to "match" the boxes, so they will register as a "match".  The "help" is of no help - only talks about widgets in general.  I'm just not understanding how to set this game up.
    Thanks for any help!
    -Michelle

    Hi
    Here is how it works.
    To get 18 boxes, you can select 3x6 grid. You get 9 boxes on the widget screen.
    In these 9 boxes, you add 9 unique images. The 9 images you add get duplicated when you close the widget. (On closing the widget, you can see 18 boxes - 9 boxes with original images + 9 duplicate copy boxes.)
    Optionally, you can click Next (the Arrow button on bottom right corner) and you can customize the start screen, game screen, and score screens. You can also change the feedback text as well.
    Click OK once you are done with the widget.
    You can take a preview / publish and match the images you added to its duplicate copies. That is the "matching" part.
    Sreekanth

  • Memory Game interation - letters with accents

    Hello, I have set up the Memory Game interaction in Cap. 7. I want the user to match English and French terms. However, any letters with accents (année = year) simply do not show up in the active game. I can indeed enter them when making up the game, but when I go to run the game, all such letters are simply ignored (omitted). Instead of année, one sees anne! What can be done? Thank you. Marvin DuBois

    Thanks again, Lilybiri. Here's to hoping . . .
    By the way, perhaps I should mention that I've found what appears to be a work-around. In Memory Game, one can insert text or pictures. I've typed out all the words in Word, and then taken snips (screenshots) of the French terms with accents. Thus far it seems to work perfectly. The terms in Word are on a white background, and I've managed to get the font size about right, and thus no appreciable difference shows up between the text and graphic versions.
    Perhaps I will run into problems at some point, i.e. perhaps the text and graphic versions will scale differently. But I don't know that this will be a problem. (I'm just preparing for the worst . . . )
    Thanks again. Marvin

  • Random Function

    Hi All!
    I am making a software which require Random numbers in the Text Field. Is facality available in Oracle Forms 6i for Random numbers.
    If yes then How?
    Help me....

    Hi,
    I used this package for generate a limited random number for a simple poker game.
    Next time use Google, I found it with it not in forum :)
    bye
    PACKAGE BODY PKG_RANDOM IS
    /* Linear congruent random number generator */
    m constant number:=100000000; /* initial conditions */
    m1 constant number:=10000; /* (for best results) */
    b constant number:=31415821; /* */
    a number; /* seed */
    the_date date; /* */
    days number; /* for generating initial seed */
    secs number; /* */
    /*-------------------------- mult ---------------------------*/
    /* Private utility function */
    function mult(p in number, q in number) return number is
    p1 number;
    p0 number;
    q1 number;
    q0 number;
    begin
    p1:=trunc(p/m1);
    p0:=mod(p,m1);
    q1:=trunc(q/m1);
    q0:=mod(q,m1);
    return(mod((mod(p0*q1+p1*q0,m1)*m1+p0*q0),m));
    end; /* mult */
    /*-------------------------- rndint --------------------------*/
    /* Returns random integer between [0, r-1] */
    function rndint (r in number) return number is
    begin
    /* generate a random number and set it to be the new seed */
    a:=mod(mult(a,b)+1,m);
    /* convert it to integer between [0, r-1] and return it */
    return(trunc((trunc(a/m1)*r)/m1));
    end; /* rndint */
    BEGIN
    the_date:=sysdate;
    days:=to_number(to_char(the_date, 'J'));
    secs:=to_number(to_char(the_date, 'SSSSS'));
    a:=days*24*3600+secs;
    END;

  • Crashing out of games randomly

    I recently installed a G4Ti4200-VTD8X, and am having problems with crashing to the desktop from Direct3D games frequently (sometimes rebooting completely).  The problem is tough to reproduce, as it seems to happen randomly.  It seems to occur most often when the system is under heavy graphics load.
    I am running the most recent Detonator drivers, the most recent drivers for my motherboard (VIA Hyperion), and the most recent version of Direct3D (I've been going back and forth with the game company as well, so I've been troubleshooting this for a while).
    I checked to see if my power supply meets the specs I found elsewhere on this board, and it is fine as well.
    I have my dxdiag file available if necessary.
    Current specs:
    Soyo Dragon Plus MB
    Athlon XP 1800+
    512 MB memory
    Does anyone have any recommendations about what to try from here?  Any help would be immensely appreciated.

    I built my wife a computer and it seems to crash randomly when she plays games (star wars galaxies).  Sometimes when playing she will get kicked to the desktop other times the computer will restart.  When the computer restarts the error "The computer has rebooted from a bugcheck.  The bugcheck was: 0x10000050 (0xe1531308, 0x00000000, 0xbf84e8fc, 0x00000001). A dump was saved in: C:WINDOWSMinidumpMini072203-02.dmp." is stored in the system part of the event viewer.
    All the computer parts are less than 2 weeks old.  The parts are as listed:
    msi ti4200-vtd8x
    maxtor 120 gig sata hard drive, 7200 rpm 8 meg cache.
    2.4 gig intel p4 cpu (800 mhz sys bus & 512k cache.
    intel d865perl motherboard, with dual-channel ddr400 mem, agp 8x slot, onboard sound & network.
    i currently have 1 gig of ddr400 mem (512 times 2).
    antec 350 watt power supply.
    samsung 52speed cd.
    this happens with the 4.1.0.7 driver (downloaded from msi), windows update driver, & the newest driver from off the nvidia website (the driver from msi seems to be more stable only crashing once every 2 hours or so, the other drivers crash about every 20 min).  This has happened befor and after i flashed the bios. Befor and after the windows update (severice packs & hot fixes). Too attemp to find the problem i have not installed any additional software.  The video card is on IRQ 16 with my usb universal host controller.  I ran the intel memory testing tool and everything passed multiple times.  I also monitor the power supply & tempature and they seem fine (bios & intel monitor)
    I have a mini dump file but am unable to decipher it.
    I would greatly appreciate any help.

  • Bios settings, memory and random freezing

    Hi all
    I have a new pc setup.  Problem is that it keeps freezing at random times, either playing a game or listening to music and sometimes just when I surf the net.  It has even frozen IN THE BIOS!! before needing a restart!
    I think that its something to do with the memory settings in the bios, any ideas on what the bios settings should be?? all components are brand new.
    MSI kt6v-lsr
    AMD Athlon XP 1700
    512mb PC400 DDR Ram
    Leadtech GeForce FX5200 128mb
    1 X Maxtor 82gb SATA drive (booting from)
    2 IDE CD drives attached.
    500w PSU
    Currently i have FSB set to 133 as any higher than that and the system wont start, the rest is set to auto.
    Any help much appreciated!! CHeers!

    A nice description about SPD,  its used to automatically detect your ram timings.
    http://www.extremeoverclocking.com/reviews/memory/Crucial_PC3200_4.html
    Now PC3200 is new but some manufacturers have PC4000 ram (500mhz)
    So the technology side should be ok.
    The problem lies with Unbranded and cheap memory modules.
    The novatech ram is unbranded and cheap  .
    You should have gone for a make like Kingston, the HyperX series are very good.
    I would recommend the HyperX PC2700 that I am using, it is capable of running at 434Mhz so if oneday you upgrade to an XP3200+ CPU (200Mhz FSB) you can set the ram to 400Mhz and it is guaranteed to work.

Maybe you are looking for

  • Importing video from Sony HDR-CX410 FCP 6.0.6 will not recognise AVCHD files. what is the solution?

    First I have to admit I'm not technical in any way so I'm easily confused so please forgive me if my question sounds unprofessional. The computer is a Mac desk top tower with Lion OS x 2x2.66 GHz Dual-Core Intel Xeon with an  internal hard drive plus

  • How to get extension version number to update in exchange panel.

    I was able to upload my Illustrator extension, set it to private and share it. Brialliant functionality. Now I have released a point update, and although it shows the correct version in the extension details on the Adobe Exchange website, the version

  • SSRS Data Driven Subscription Split Report on Email

    I have a requirement to email an SSRS report to each of the individual emails referenced in the report. Think of it is as a mail merge wherein there are 5 persons receiving the report.The Current SSRS Report contains 5 Letters. The Email Subscription

  • ORAMED-01002:[Metadata error in assign operation]

    Im using the Oracle Mediator component to assign an expression to a property. The assign expression uses the dvm:lookupValue() function to assign the outcome of the function to the property. When I invoke a message from e.g. SoapUI or the em testfeat

  • Changing a generic datasource

    Hi all, I already have a datasource which is created through view which is already available in production.Now we want to just add a field  and we have for it in he view table itself.Can someone tell my the steps how to do it.I have done it  and i ca