Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to create a matching game by drawing a line !

New Here ,
Mar 25, 2013 Mar 25, 2013

hi

i want to create a matching game by line

the idea is a scene contain list in righ and list in left

and the user drow a line between the two list

what is the code that create a line in specific point to another specific point

or any other solution to achive the same idea !

TOPICS
ActionScript
4.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 25, 2013 Mar 25, 2013
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 25, 2013 Mar 25, 2013

There was similar question before - see my answer in the thread:

http://forums.adobe.com/message/4632809

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 25, 2013 Mar 25, 2013

well i saw both links but i didint catch any thing to understand

i have 4 movie clips on the left and 4 on the right

on the drag and drop codes

i want when drag a line starts and till he reach the right target with mouse

and drop the mouse so the line complete

and when it reach the wrong distination

a wrong msg appers (alpha = 1);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 25, 2013 Mar 25, 2013

Look at the graphics object for drawing: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html

It's accessible through Sprite.graphics and MovieClip.graphics.

Your basic idea would be:

object.graphics.lineStyle(3);

object.graphics.moveTo(startX, startY);

object.graphics.lineTo(finalX, finalY);

For you startX and startY would be where the mouse was down initially (or your target point for first list) and the finalX and finalY would be where the user released the mouse (or your target point for the second list)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 25, 2013 Mar 25, 2013

great i tried and its work fine

but how i use if here !

for examlple

object.graphics.lineStyle(3);

object.graphics.moveTo(rectX, rectY);

and if the final is right then :

object.graphics.lineTo(finalX, finalY);

lets say i have 3 movie clips and ( rect1 , rect3, rect3 )

i wont rect1 connect to rect2

so if the user went to rect 3

a (X) appers by alpha= 1

but if he went to rect 2 then complete the line

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2013 Mar 27, 2013

ok its killing me

here the codes

its a matching game with 2 classes

package

{

          import flash.display.*;

          import flash.events.*;

          public class DragDrop extends Sprite

          {

                    var origX:Number;

                    var origY:Number;

                    var target:DisplayObject;

                                        var mc:MovieClip = new MovieClip();

 

                    public function DragDrop()

                    {

                              // constructor code

                              origX = x;

                              origY = y;

 

                              addEventListener(MouseEvent.MOUSE_DOWN , drag);

                    }

                    function drag(evt:MouseEvent):void

                    {

                              stage.addEventListener(MouseEvent.MOUSE_UP , drop);

                              startDrag();

                              parent.addChild(this);

                    }

                    function drop(evt:MouseEvent):void

                    {

                              stage.removeEventListener(MouseEvent.MOUSE_UP, drop);

                              stopDrag();

 

                              if(hitTestObject(target))

                              {

                                        visible = false;

                                        target.alpha = 1;

 

mc.graphics.beginFill(0x000000);

mc.graphics.lineStyle(5,0x000000);

mc.graphics.moveTo(origX,origY);

mc.graphics.lineTo(target.x,target.y);

mc.graphics.endFill();

                                        Object(parent).match();

 

                              }

 

                              x = origX;

                              y = origY;

 

                    }

          }

}

and

package

{

          import flash.display.*;

          import flash.events.*;

          public class Map extends MovieClip

          {

                    var dragdrops:Array;

                    var numOfMatches:uint = 0;

                    var speed:Number = 25;

                    var winSound:heeh = new heeh();

                    public function Map()

                    {

                              // constructor code

                              dragdrops = [ihard,iwesh,iloop];

                              var currentObject:DragDrop;

                              for (var i:uint = 0; i < dragdrops.length; i++)

                              {

                                        currentObject = dragdrops;

                                        currentObject.target = getChildByName(currentObject.name + "_target");

 

                              }

 

                    }

                    public function match():void

                    {

                              numOfMatches++;

                              if (numOfMatches == dragdrops.length)

                              {

                                        win.addEventListener(Event.ENTER_FRAME, winGame);

                              }

                              function winGame(event:Event):void

                              {

                                        win.y -=  speed;

                                        if (win.y <= 0)

                                        {

                                                  win.y = 0;

                                                  win.removeEventListener(Event.ENTER_FRAME, winGame);

                                                  win.addEventListener(MouseEvent.CLICK, clickWin);

                                                  winSound.play();

                                        }

                              }

                              function clickWin(event:MouseEvent):void

                              {

                                        win.removeEventListener(MouseEvent.CLICK, clickWin);

                                        win.addEventListener(Event.ENTER_FRAME, animateDown);

                                        var currentObject:DragDrop;

                                        for (var i:uint = 0; i < dragdrops.length; i++)

                                        {

                                                  currentObject = dragdrops;

                                                  getChildByName(currentObject.name + "_target").alpha = 0;

                                                  currentObject.visible = true;

                                        }

                                        numOfMatches = 0;

                                        addChild(win);

                                        function animateDown(event:Event):void

                                        {

                                                  win.y +=  speed;

                                                  if (win.y >= stage.stageHeight)

                                                  {

                                                            win.y = stage.stageHeight;

                                                            win.removeEventListener(Event.ENTER_FRAME, animateDown);

                                                  }

                                        }

                              }

                    }

          }

}

so i use this code

mc.graphics.beginFill(0x000000);

mc.graphics.lineStyle(5,0x000000);

mc.graphics.moveTo(origX,origY);

mc.graphics.lineTo(target.x,target.y);

mc.graphics.endFill();

to drow the line

but it didnt work

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 27, 2013 Mar 27, 2013

1. if You use classes use scope ( private function drag etc)

2.trace your value for origX,origyY, targetX, targety, you might have a problem with local vs global coordinatesystems

but it didnt work

what exactly?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 28, 2013 Mar 28, 2013
LATEST

the line

alll i want is

when hitting object 

a line draw between the two mc

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines