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

Path Drawing App

New Here ,
Jan 02, 2013 Jan 02, 2013

Hi All,

I'm having a problem with a Flash App that i'm trying to develop...

Basically i'm creating a program which allows a user to draw up to 3 paths onto the Flash stage by clicking different options in a pallete located at the side of the screen. These paths will be created in different layers (MovieClips) in three different colours. As yet i've only allowed the creation on the first path which is blue. The path is made up of different segments so when the user clicks the straight line button a straight line graphic is placed onto the stage. If the user then clicks the right angle button a right angle is placed onto the stage, its origin is set to the end point of the last segment placed onto the stage so it builds a path. i have several different buttons which create different angled pieces allowing the path to go in different directions. This all works fine as pictured...

1.jpg

The problem comes when the path becomes too large and leaves the stage. At this point i want the layer movieclip to scale by say 50 percent and center itself on the stage. So an auto zoom out effect to keep the drawing visible. This also works fine. However once the clip has been scaled the coodinates all go wrong. So when the user clicks to create another piece of the path it doesn't place it at the end of the last segment. I've been racking my brains with this and just can't seem to come up with a solution. The coordinates to which the next piece of path is placed is obtained by using localToGlobal on a movieclip which is nested in the last piece placed onto the stage. Surely even though the layer movieclip has been scaled the localToGlobal method should still be able to return the right coordinate?? Clearly i'm missing something here : (

See pic below, as you can see after the layer is scaled the coordinates seem to go all strange even though they are collected on each button click via localToGlobal

2.jpg

Any help would be massively appreciated!

Many Thanks

M

TOPICS
ActionScript
1.0K
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

correct answers 1 Correct answer

Community Expert , Jan 03, 2013 Jan 03, 2013

no, you're not using localToGlobal correctly.  that method returns a point so, instead of this:

   var pt3:Point = new Point(MovieClip(root).blueLayer.newStraightLine.joint2MC,MovieClip(ro ot).blueLayer.newStraightLine.joint2MC);

   pt3 = (newStraightLine.joint2MC.localToGlobal(pt3),newStraightLine.joint2MC .localToGlobal(pt3));

   globalPoint = pt3;

you should be using:

   var pt3:Point = new Point(MovieClip(root).blueLayer.newStraightLine.joint2MC,MovieClip(ro ot).blueLayer.newStraightLine.joint2MC

...
Translate
LEGEND ,
Jan 02, 2013 Jan 02, 2013

You'll need to show the code that is relevant to the problem.

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 ,
Jan 02, 2013 Jan 02, 2013

Hi Ned, Thanks for your reply...

This is the code for the conrol panel class...

I think the problem lies somewhere with the localToGlobal part near the bottom of the addStraighline function. Perhaps i'm not using it correctly?

package  {

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Matrix;


public class commandsMC extends MovieClip {
 
   public var blueObjectsList:Array = new Array;
   public var newStraightLine:straightLineMC = new straightLineMC();
   public var globalPoint:Point = new Point(720,810);
   public var pathDirection:int = new int(0);

public function commandsMC() {
   straightLineBTN.addEventListener(MouseEvent.CLICK, addStraightLine);
  }
 


public function addStraightLine(e:MouseEvent):void {
  
  
   newStraightLine = new straightLineMC();
   MovieClip(root).blueLayer.addChild(newStraightLine);
   newStraightLine.x = globalPoint.x ;
   newStraightLine.y = globalPoint.y ;
  
   blueObjectsList.push(newStraightLine);
  
  
   switch (pathDirection){

  
   case 0:
   newStraightLine.rotation = pathDirection;
   break;
  
   case 45:
   newStraightLine.rotation = pathDirection;
   break;
  
   case 90:
   newStraightLine.rotation = pathDirection;
   break;
  
   case 135:
   newStraightLine.rotation = pathDirection;
   break;
  
   case 180:
   newStraightLine.rotation = pathDirection;
   break;
  
   case 225:
   newStraightLine.rotation = pathDirection;
   break;
  
   case 270:
   newStraightLine.rotation = pathDirection;
   break;
  
   case 315:
   newStraightLine.rotation = pathDirection;
   break;
  
   }
  
   hitTest();


   var pt3:Point = new Point(MovieClip(root).blueLayer.newStraightLine.joint2MC,MovieClip(root).blueLayer.newStraightLine.joint2MC);
   pt3 = (newStraightLine.joint2MC.localToGlobal(pt3),newStraightLine.joint2MC.localToGlobal(pt3));
   globalPoint = pt3;
  
  
  
   }
}

}


public function scaleFromCenter(ob:*, sx:Number, sy:Number, ptScalePoint:Point) {
var m:Matrix=ob.transform.matrix;
m.tx -= ptScalePoint.x;
m.ty -= ptScalePoint.y;
m.scale(sx, sy);
m.tx += ptScalePoint.x;
m.ty += ptScalePoint.y;
ob.transform.matrix = m;
}

public function hitTest():void {
  if (newStraightLine.hitTestObject(MovieClip(root).limitTop)){
   workAreaBreach();
  }
}
 

public function workAreaBreach():void {
 
   var ptScalePoint:Point = new Point(MovieClip(root).blueLayer.width/2,MovieClip(root).blueLayer.height/2);
   scaleFromCenter(MovieClip(root).blueLayer, 0.5, 0.5, ptScalePoint);
  
}

This is the code for the document class...

package  {

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;


public class Path_Generator extends MovieClip {
 
   public var blueLayer:blueLayerMC = new blueLayerMC;
   public var controlPanel:commandsMC = new commandsMC;

  public function Path_Generator() {
  
   addChild(blueLayer);
   addChild(controlPanel);
   controlPanel.x = 1324.25;
   controlPanel.y = 0;
  
   }
  
  


  
  
 


  }
  
  
}

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
Community Expert ,
Jan 02, 2013 Jan 02, 2013

actually, you can scale to 100% x 100% add your next segment per your usual, then scale back down again.

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 ,
Jan 03, 2013 Jan 03, 2013

Ah now that is a simple idea! Thankyou i will give it a try. I just wondered if i was using the localToGlobal method incorrectly. It just seems odd to me that it won't work once the container layer is scaled as its still doing the same thing as before its scaled?!

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
Community Expert ,
Jan 03, 2013 Jan 03, 2013
LATEST

no, you're not using localToGlobal correctly.  that method returns a point so, instead of this:

   var pt3:Point = new Point(MovieClip(root).blueLayer.newStraightLine.joint2MC,MovieClip(ro ot).blueLayer.newStraightLine.joint2MC);

   pt3 = (newStraightLine.joint2MC.localToGlobal(pt3),newStraightLine.joint2MC .localToGlobal(pt3));

   globalPoint = pt3;

you should be using:

   var pt3:Point = new Point(MovieClip(root).blueLayer.newStraightLine.joint2MC,MovieClip(ro ot).blueLayer.newStraightLine.joint2MC);

   globalPoint= newStraightLine.joint2MC.localToGlobal(pt3);

p.s. please mark helpful/correct responses.

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