A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Problem matching arrays for flashcards activity: answers to random images

  1. #1
    Junior Member
    Join Date
    Sep 2005
    Location
    Scotland
    Posts
    7

    Cool Problem matching arrays for flashcards activity: answers to random images

    Hi folks
    Making a flashcards actvity - self-test, in which user just has to think of the answer and then see if they were right.

    How it works:
    A button randomly shows an image from a dynamically-produced array of images (movieclips) then switches to a button to show the answer from a static array of strings.

    I'm having problem matching the answers to the randomly displayed images. The best I can do is show the last answer only - no matter what image is showing. So I think maybe I'm not too far way, but I've evidently done something wrong!

    I've attached the script (rather than the FLA as folk use different versions) which sits in the first frame. Paste this into the first frame to see it working so far.

    If anyone can help me with the correct solution that would be great .
    Attached Files Attached Files

  2. #2
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760

    missing class objects in library for that to work

    Scene 1, Layer 'Layer 1', Frame 1, Line 68 1046: Type was not found or was not a compile-time constant: goNext.
    Scene 1, Layer 'Layer 1', Frame 1, Line 35 1180: Call to a possibly undefined method picHolder.
    Scene 1, Layer 'Layer 1', Frame 1, Line 66 1180: Call to a possibly undefined method startMe.
    Scene 1, Layer 'Layer 1', Frame 1, Line 67 1180: Call to a possibly undefined method amRight.
    Scene 1, Layer 'Layer 1', Frame 1, Line 68 1180: Call to a possibly undefined method goNext.
    Scene 1, Layer 'Layer 1', Frame 1, Line 67 1046: Type was not found or was not a compile-time constant: amRight.
    Scene 1, Layer 'Layer 1', Frame 1, Line 66 1046: Type was not found or was not a compile-time constant: startMe.
    Scene 1, Layer 'Layer 1', Frame 1, Line 35 1046: Type was not found or was not a compile-time constant: picHolder.
    [SIGPIC][/SIGPIC]

  3. #3
    Junior Member
    Join Date
    Sep 2005
    Location
    Scotland
    Posts
    7

    Cool

    Hy Rynoe
    Sorry, brain must have been frazzled - should really have sent the FLA. Have attached FLA - it's CS4 I'm afraid as that's all I have at home (CS5 at work).
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Posts
    1

    Just a couple small changes

    Hi zubaran,

    You're very close. You can set up your "answer" variable right away when you're creating the allPics Array:
    Code:
    for (var i:int = 1; i<=numPics; i++)
    {
    	var thePic:Class = getDefinitionByName("pic" + i) as Class;
    	var myPic:MovieClip = new thePic();
    	myPic.name = "pic" + i;
    	myPic.answer = allAnswers[i-1];	// ADDED LINE
    	allPics.push(myPic);
    }
    This is a convenient place to set up the answer variable because you're going through the cards one by one anyway.

    And then in showAnswer(), when the user has clicked on the "Am I right?" button, get the answer variable from the current card. However, do not use myPic because that actually refers to the myPic in the last pass through the for loop above. The current card is the allPics[nextCard] that you're removing from the card holder.

    Code:
    function showAnswer(event:MouseEvent):void
    {
    	checkMe.visible = false;
    	theAnswer.text = allPics[nextCard].answer;	// ADDED LINE
    	holder.removeChild(allPics[nextCard]);
    	theAnswer.visible = true;
    	nextFC.visible = true;
    }

  5. #5
    Junior Member
    Join Date
    Sep 2005
    Location
    Scotland
    Posts
    7
    Hi ascomeau
    That's great! - It worked - I can't believe I was so close after going round in circles!
    Many thanks my man - you're a star

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center