Skip navigation
Currently Being Moderated

HELP. I need some code for "draw a line to match" learning activity

Aug 19, 2012 3:48 PM

Tags: #flash #actionscript #as3.0 #game #actionscript3

Dwaw a line to match answers with questions - elearning activity for my classroom

 

I need some AS3 code for drawing lines between Movieclips to match questions with answers. I have 7 questiions and 7 answers. I also need some feedback like "Correct" and "Try again". also it needs to have a counter so I know when its complete.

 

Thanks so much!

 

draw a line.PNG

 
Replies
  • Currently Being Moderated
    Aug 19, 2012 4:28 PM   in reply to TimsterVideo

    Forums are places to get help with problems.  People do not generally do others work for them here unless you hire them.  Show the code and explain the problem you are having with it.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2012 5:24 PM   in reply to TimsterVideo

    Here is a quick and dirty mockup. Just make this class a document class in a fresh fla:

     

     

    package {
          import flash.display.Sprite;
          import flash.text.TextField;
          import flash.text.TextFieldAutoSize;
          import flash.text.TextFormat;
          public class Help extends Sprite
          {
                private var panelHeight:Number = 30;
                private var panelWidth:Number = 100;
                private var questionsUI:Vector.<Sprite> = new Vector.<Sprite>();
                private var answersUI:Vector.<Sprite> = new Vector.<Sprite>();
                private var qColors:Vector.<uint> = new <uint>[0xC40000, 0xFF712D, 0x008000, 0x5353FF, 0x800040, 0xFF0080, 0x0000FF];
                private var answerFillColor:uint = 0x00C663;
                private var sprite:Sprite;
                private var gap:Number = 10;
                private var numQuestions:int = 7;
                private var i:int = 0;
     
                public function Help()
                {
                      init();
                }
      
                private function init():void 
                {
                      for (i = 0; i < numQuestions; i++) {
                            questionsUI.push(drawRect("Question " + i, qColors[i], 0xFFFFFF));
                            answersUI.push(drawRect("Answer " + i, answerFillColor));
                      }
       
                      placeObjects();
                      drawConnectors();
                }
      
                private function drawConnectors():void 
                {
       
                      for (i = 0; i < numQuestions; i++) {
                            graphics.lineStyle(2, qColors[i]);
                            sprite = questionsUI[i];
                            graphics.moveTo(sprite.x + sprite.width, sprite.y + sprite.height * .5);
                            sprite = answersUI[i];
                            graphics.lineTo(sprite.x, sprite.y + sprite.height * .5);
                      }
                }
      
                private function placeObjects():void 
                {
                      placeCollection(questionsUI, gap);
                      placeCollection(answersUI, panelWidth + 200);
                }
      
                private function placeCollection(v:Vector.<Sprite>, xPos:Number):void {
                      var tempVector:Vector.<Sprite> = v.slice();
                      var r:int;
                      var nextY:Number = gap;
                      while (tempVector.length > 0) {
                            r = Math.random() * tempVector.length;
                            sprite = tempVector[r];
                            addChild(sprite)
                            sprite.x = xPos;
                            sprite.y = nextY;
                            nextY += sprite.height + gap;
                            tempVector.splice(r, 1);
                      }
                }
      
     
                private function drawRect(text:String, fillColor:uint, color:uint = 0x000000):Sprite {
                      var t:TextField = new TextField();
                      t.autoSize = TextFieldAutoSize.LEFT;
                      t.defaultTextFormat = new TextFormat("Arial", 12, color);
                      t.text = text;
                      t.x = 6;
                      t.y = (panelHeight - t.height) * .5;
                      sprite = new Sprite();
                      sprite.graphics.beginFill(fillColor);
                      sprite.graphics.drawRoundRect(0, 0, panelWidth, panelHeight, 5);
                      sprite.addChild(t);
                      return sprite;
                }
      
          }
    }
     
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2012 6:28 PM   in reply to TimsterVideo

    You don't have to do anything - just make it a doc class.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points