Understanding LocalToGlobal ?
Hello,
I´m trying to use the localToGlobal function but I don't seem to get the results I need. However the problem is simple.
I have a movieclip M1 and inside this movieclip are 2 other movieclips M2 and M3. M3 contains instance of M2. What I am trying to do is to move the _root.M1.M2 movieclip to the position of the _root.M1.M3.M2 so they match exactly ( M2 contains a simple shape of a box so when the position of the two movieclips match they will be lying above each other so it will look like one box).
So what I really need is _root.M1.M3.M2 position inside _root.M1
I have tryid this:
point = new Object ();
point.x = _root.M1.M3.M2._x;
point.y = _root.M1.M3.M2._y;
_root.M1.localToGlobal (point);
_root.M1.M2._x = point.x;
_root.M1.M2._y = point.y;
However the _root.M1.M2 movieclip doesn't end in same position as the _root.M1.M3.M2 movieclip.
Anyone know how to manage this ???
Thank you.
FlashKit > Flash Help > Flash MX
Posted on: 07-25-2003, 06:55 AM
View Complete Forum Thread with Replies
Sponsored Links:
Understanding LocalToGlobal ?
Hello,
I´m trying to use the localToGlobal function but I don't seem to get the results I need. However the problem is simple.
I have a movieclip M1 and inside this movieclip are 2 other movieclips M2 and M3. M3 contains instance of M2. What I am trying to do is to move the _root.M1.M2 movieclip to the position of the _root.M1.M3.M2 so they match exactly ( M2 contains a simple shape of a box so when the position of the two moviclips match they will be lying above each other so it will look like one box).
So what I really need is _root.M1.M3.M2 position inside _root.M1
I have tryid this:
point = new Object ();
point.x = _root.M1.M3.M2._x;
point.y = _root.M1.M3.M2._y;
_root.M1.localToGlobal (point);
_root.M1.M2._x = point.x;
_root.M1.M2._y = point.y;
However the _root.M1.M2 movieclip doesn't end in same position as the _root.M1.M3.M2 movieclip.
Anyone know how to manage this ???
Thank you.
View Replies !
View Related
Localtoglobal
Hi Everyone,
When I load a movie into level one in Flash5 I would like to be able to assign it "x,y" coordinates. I gather this can be done with "localtoglobal". I can't seem to figure out the script. Any help would be much appreciated. Thanks.
JR
View Replies !
View Related
LocalToGlobal
~~~You may need to look into using the localToGlobal method for converting MC coordinates to the main timeline~~~
Hi folks the above was a sugestion for a query I had earlier, thanks to deadbeat... What I was now wanting is someone who knows how to do this???
Below is the original question and response
-------------------------------------------------------
my question<<<
Ok!! I have my main swf index.swf into this I'm loading some other .swf with loadmov action some just at a certain point and others onclick, one of the .swf that I load into this main movie (dragmov.swf) has a drag and drop point so if you drop it somewhere it puts it back to its original spot... This works fine when I export dragmov.swf and view it, but when It loads into the main movie everything works except the drop point, WHY????
-------------------------------------------------------
deadbeat responce<<
This is because movieclips and loaded movies each have their own internal coordinate system...so an x position of 100 in a movieclip is not necessarily the same as an x position of 100 on the main timeline...
You may need to look into using the localToGlobal method for converting MC coordinates to the main timeline...
HTH,
-------------------------------------------------------
Thanks to any who can help!!!
D
View Replies !
View Related
LocalToGlobal ?
Hi all,
I'm making a movie involving various rotating clips. Each clip has another clip at each end which I'm using to track positions.
I have used localToGlobal and globalToLocal before with success but in this case, it doesn't work. Is this because the clips are rotating rather than moving? If so, is there another way I could find out the global positions of the clips?
Any help would be much appreciated.
View Replies !
View Related
LocalToGlobal()
I'm having some trouble getting the localToGlobal function to work properly. What I need is for Image1.pe.gun_s' x and y coordinates to be the global coordinates for Image1, and the same for Image2.gun.gun_p and Image2. I've tried using this method, but it's not functioning correctly.
Code:
point = new Object();
point.x = Image1.pe.gun_s._x;
point.y = Image1.pe.gun_s._y;
Image2.localToGlobal(point);
point2 = new Object();
point2.x = Image2.gun.gun_p._x;
point2.y = Image2.gun.gun_p._y;
Image2.localToGlobal(point2);
point.x = point2.x;
point.y = point2.y;
If point.x and point2.x are traced, they return the same coordinates, which is what I want. However, the Images do not move at all. It almost seems like I'm missing something in my code to add the Image to the actual Object that's being created. Thoughts?
View Replies !
View Related
LocalToGlobal...?
Hey,
Here's my problem. Say I have an MC with the instance name of 'player'. In that MC is another MC with the instance name of 'arm'. Now, in my code on the first frame of the root timeline, I make the player MC move. If I were to trace the x and y coordinates of the player MC, it'd constantly be changing. If I were to trace the x and y coordinates of the arm MC within the player MC, however, the coordinates would never change. This is because I never actually move that MC itself. That's fine.
Now, let's say I did want to actually find the arm's x and y coordinates in relation to the main stage. As if the x and y coordinates of it were on the root timeline. I read that I could use "localToGloba()", and I've tried, but it didn't work. This is what I tried:
code: player.arm.localToGlobal();
localToGlobal(player.arm);
And others. I read in the Actionscript dictionary that the parameter of localToGlobal is the "point", which is an Object object that you set an x and y for. I didn't exactly understand this. If anyone could explain to me how this works, and how I could fix my problem, that'd be great. =)
Thanks,
~ Pol
View Replies !
View Related
LocalToGlobal Help
To main MCs. There are another MovieClips embedded in each of them.
-- plates_mc ---> plate_1_mc
-- lib_mc ---> rec_1_mc
Aim:
If i click on plate_1_mc, then rec_1_mc shall move on the middle of plate_1_mc.
Plz help.
View Replies !
View Related
LocalToGlobal
I'll try to explain this as easily as i can. On my main timeline. I have a turret that rotates to the player. Inside the turret movieclip I have the barrel (of the gun) movieclip. On the first frame of that movieclip there is this code to shoot at the player:
Code:
var count = 0;
var wait = 50;
var numbullets = 0;
var speed = 20;
onEnterFrame = function() {
var p:Object = {x:0, y:0}
this.localToGlobal(p);
var dx = _root.hero._x - p.x
var dy = (_root.hero._y - (_root.hero._height/2)) - p.y
var angle = Math.atan2(dy, dx);
_rotation = angle * 180 / Math.PI
if (count == wait){
count = 0;
numbullets += 1;
var newBullet = _root.platform.attachMovie("statmissile", "bullet_" + numbullets, getNextHighestDepth());
this.gotoAndPlay();
//// HERE : \\\
var barrelPoint = new Object;
barrelPoint.x = this.point._x;
barrelPoint.y = this.point._y;
this.localToGlobal(barrelPoint);
newBullet._x = barrelPoint.x;
newBullet._y = barrelPoint.y;
/////// TO HERE \\\\\\
newBullet._rotation = this._rotation;
newBullet.mcHeight= this.mcHeight;
newBullet.mcWidth= this.mcWidth;
newBullet.xSpeed = (barrelPoint.x - this._x) / speed;
newBullet.ySpeed = (barrelPoint.y - this._y) / speed;
newBullet.point = new Object;
newBullet.onEnterFrame = function() {
this._x -= this.xSpeed;
this._y -= this.ySpeed;
if (this._x < 0 || this._y < 0 || this._x > this.mcWidth || this._y > this.mcHeight) {
this.removeMovieClip();
}
}
} else {
count += 1;
}
}
The part in between the "here" signs is where i am having trouble. the missile is attached at the wrong coordinates. I think it has something to do with the localToGlobal(); function but i cant tell. Can anyone help? Tell me if i didn't explain well.
View Replies !
View Related
LocalToGlobal
Hey all, I'v been reading up a little on this, but I just dont get it, could someone please enlighten me. Im simply trying to get the global position of a movie clip which is nested within another so I can use that information to stop another mc in the correct place, but I cant work out how to go about it with this.
Any help is appreciated.
View Replies !
View Related
LocalToGlobal?
How does localToGlobal work in AS3? I googled it and I'm doing it this way... but it doesn't work:
ActionScript Code:
//mc2.hitobj[q] is a point object located within an array called hitobj
//these are the coordinates before doing local to global
trace("local "+mc2.hitobj[q].x+","+mc2.hitobj[q].y);
//perform local to global
localToGlobal(mc2.hitobj[q]);
//these are the coordinates after doing local to global
trace("global "+mc2.hitobj[q].x+","+mc2.hitobj[q].y);
And the trace output is this... obviously, something's wrong. These are still the local coords.
ActionScript Code:
local 17.25,3.6
global 17.25,3.6
View Replies !
View Related
LocalToGlobal?
I can't seem to get this right... I have two Sprites that need to be dragged together. So i don't use startDrag(). I have to create a onMouseMove event (that is no problem i have that working)
i store the mouseX, mouseY positions and store them before i start dragging, that way the center of the dragging position will be where you clicked.
this works great, UNLESS the user rotated the Sprite. The the Sprite jumps whe I click on it and starts dragging, instead of being seamless.
I tried to look up localToGlobal and globalToLocal, but i just don't get it...
how do i make this work?
thanks,
bryan
View Replies !
View Related
Localtoglobal
Hey! I want create a fillshape that covers the entire background inside att nested mc.
Since i create it in a nested movieclip i want be able to place it on the x=0 and y=0 of the main stage, not the x=0 and y=0 of the clip it is in.
So i thought i would use localtoglobal for this. Is it possible? Tried something like this, but i get errors.
ActionScript Code:
var point:Object = {x:0,y:0};
var shape:Shape = new Shape();
shape.graphics.lineStyle(1);
shape.graphics.beginFill(0);
shape.graphics.drawRect(0, 0, stage.width, stage.height);
shape.graphics.endFill();
_fadedBackground.addChild(shape);
_fadedBackground.localToGlobal(point);
_fadedBackground.x = point.x;
_fadedBackground.y = point.y;
addChild(_fadedBackground);
View Replies !
View Related
LocaltoGlobal()
PHP Code:
point = new object();
point.x = this.loop.loopBlack.tip._x
point.y = this.loop.loopBlack.tip._y
trace(point.x + " < > " + point.y);
localToGlobal(point);
trace(point.x + " < - > " + point.y);
according to my knowledge the x,y coordinates of
this.loop.loopBlack.tip after the function localToGlobal(point); is ran, would convert it to the coordinates in respect to the stage right?
somehow it is not doing that for me
View Replies !
View Related
LocalToGlobal
For whatever reason I'm having trouble grasping the localToGlobal concept.
ActionScript Code:
this.controller.drawer.bg.onPress = function(){
this.controller.drawer.bg.diamond = _xmouse;
}
So, when I click on bg I want the diamond to move to the _xmouse position on the _root level. I'm assuming I need to convert this.controller.drawer.bg.diamond._x from localToGlobal. How would I go about doing this?
View Replies !
View Related
LocalToGlobal
basically i placed this function on the root level of my main.swf
i want to be able to call the function so my pointer animation will be dynamically loaded -10 pixels from the MC which called the function and half of the MC's height. please help me out as I'm sure it has to do with the localToGlobal point system, but can't figure the functionality.
function setPointer(mc){
this.createEmptyMovieClip("pointer", this.getNextHighestDepth());
var point:Object = {x:mc._x, y:mc._y};
this.pointer.globalToLocal(point);
this.pointer._x = mc._x-10;
this.pointer._y = mc._y+(mc._height/2);//place arrow half of text
this.pointer.attachMovie("arrow_mc", "arrow1", this.getNextHighestDepth());
};
if this can also be cleaned up, please advise as well.
View Replies !
View Related
How To Use LocalToGlobal()
Hello. I am creating a simple breakout game. When the user hits a block, the block is removed from the display list and a new plane object is created in its place. The problem is the newly created plane movie is never in the same place as the removed block. It is at some other weird point. I also tried to use localToGlobal() which I never succeed. Whenever I try to make a game with Flash (especially scroller ones) I always have trouble with its coordinate spaces. Anyway, here is the code. Please help me. This is my worst problem with Flash.
Attach Code
stop();
import fl.transitions.Tween;
import fl.transitions.*;
var ball:Ball;
var boundary:Rectangle=new Rectangle(30,30,550,350);
var ballSpeed:uint=15;
var ballxDir:int=1;
var ballyDir:int=1;
var numBalls:uint=3;
var numGifts:uint=10;
var gifts:Array=new Array();
var blocks:Array=new Array();
var moveBlocks:Tween = new Tween(blocks_mc, "x", null, 350, -1000, 10, true);
//moveBlocks.stop();
Mouse.hide();
createBall();
createGifts();
moveBlocks.addEventListener(TweenEvent.MOTION_FINISH,replay);
function replay(te:TweenEvent) {
moveBlocks.yoyo();
}
stage.addEventListener(Event.ENTER_FRAME,checkCollision);
stage.addEventListener(Event.ENTER_FRAME,moveBall);
stage.addEventListener(MouseEvent.MOUSE_MOVE,moveBar);
function createGifts() {
for (var i:uint=0; i<numGifts; i++) {
var tempGift:uint= Math.round(Math.random()*107);
gifts.push(tempGift);
}
gifts.sort(Array.NUMERIC);
}
function checkCollision(e:Event) {
for (var i:uint=0; i<blocks_mc.numChildren; i++) {
var tempBlock:DisplayObject=blocks_mc.getChildAt(i);
var suffix:String=tempBlock.name.substring(1);
if (tempBlock.hitTestPoint(ball.x,ball.y)) {
for (var j:uint=0; j<gifts.length; j++) {
if (suffix==gifts[j]) {
var tempPoint:Point=new Point(tempBlock.x,tempBlock.y);
var origin:Point=tempBlock.localToGlobal(tempPoint);
flyGifts(origin.x,origin.y);
gifts.splice(j,1);
}
}
blocks_mc.removeChild(tempBlock);
ballxDir*=-1;
ballyDir*=-1;
}
}
if (bar_mc.hitTestObject(ball)) {
//ballxDir*=-1;
ballyDir*=-1;
ball.y-=10;
}
if (ball.x<boundary.left) {
ballxDir*=-1;
ball.x+=10;
}
if (ball.x>boundary.right) {
ballxDir*=-1;
ball.x-=10;
}
if (ball.y<boundary.top) {
ballyDir*=-1;
ball.y+=10;
}
if (ball.y>boundary.bottom) {
ballyDir*=-1;
}
}
function flyGifts(px:Number,py:Number) {
var plane:Plane=new Plane();
//var planeOrigin:Point=plane.localToGlobal(p);
plane.x=px;
plane.y=py;
addChild(plane);
}
function createBall() {
if (numBalls ==0) {
//endGame();
}
ball=new Ball();
ball.x=bar_mc.x+bar_mc.width/2;
ball.y=bar_mc.y-30;
//numBalls--;
addChild(ball);
}
function moveBall(e:Event) {
ball.x+=ballxDir*ballSpeed;
ball.y+=ballyDir*ballSpeed;
}
function moveBar(me:MouseEvent) {
bar_mc.x=mouseX;
if (bar_mc.x<boundary.left) {
bar_mc.x=boundary.left;
}
if (bar_mc.x>boundary.right) {
bar_mc.x=boundary.right;
}
}
View Replies !
View Related
Help With LocalToGlobal()
I'm working on an isometric-view prototype game, and I thought a good way to do the collision detection would be to put four empty movie clips on each of the character's base corners (it's a cube), convert those corner's _x and _y to the Stage, and go from there. Problem is, I have almost no clue how to get it to work.
My character is on the stage in an otherwise empty "clip" MovieClip. Here's what I have inside my character:
Code:
onClipEvent(enterFrame){
var point:Object = new Object();
point.rightX = right._x;
point.rightY = right._y;
point.bottomX = bottom._x;
point.bottomY = bottom._y;
point.leftX = left._x;
point.leftY = left._y;
point.upX = up._x;
point.upY = up._y;
_root.localToGlobal(point);
swapDepths(_x+_y*_root.isoPlane_width);
}
Whenever I trace any of these, it always traces the local coordinates. Otherwise, everything is fine. Does anybody know why this isn't working? It's driving me nuts!
View Replies !
View Related
Help With LocalToGlobal()
I'm working on an isometric-view prototype game, and I thought a good way to do the collision detection would be to put four empty movie clips on each of the character's base corners (it's a cube), convert those corner's _x and _y to the Stage, and go from there. Problem is, I have almost no clue how to get it to work.
My character is on the stage in an otherwise empty "clip" MovieClip. Here's what I have inside my character:
Code:
onClipEvent(enterFrame){
var point:Object = new Object();
point.rightX = right._x;
point.rightY = right._y;
point.bottomX = bottom._x;
point.bottomY = bottom._y;
point.leftX = left._x;
point.leftY = left._y;
point.upX = up._x;
point.upY = up._y;
_root.localToGlobal(point);
swapDepths(_x+_y*_root.isoPlane_width);
}
Whenever I trace any of these, it always traces the local coordinates. Otherwise, everything is fine. Does anybody know why this isn't working? It's driving me nuts!
View Replies !
View Related
LocalToGlobal Help (i Think)
Hi.
I have a function to create a 20x20 grid, which works ok.
The grid's tiles are linked to a class called "Tile", and right now i have it so when the tile is clicked it puts a turret in the center of the tile
code:
Actionscript Code:
function onPress(){
if(this.used != 1){
turret = attachMovie("turret", "turret", getNextHighestDepth());
point = {x: this._x, y: this._y};
turret.localToGlobal(point);
this.used = 1;
}//end if this.used
}//end onPress
Now im using a class called "Turret" to control any turrets that are spawned, but its causing me problems with their aiming.
im pretty sure its because the coords it is using are local and not global, but im struggling to convert them.
Ive tried the same as in the tile class but it has no effect.
the code im using to make the turret aim is:
Actionscript Code:
myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
myDegrees = Math.round((myRadians*180/Math.PI));
_rotation = myDegrees + 90;
please help, it feels like i cant go anyfurther without this
thankyou,
Gareth
View Replies !
View Related
LocalToGlobal [...]
Hello!
I have to mc's, box_mc and box2_mc within the first one, and this piece of code in the first frame of root timeline:
ActionScript Code:
coord = new Object();
coord.x = box_mc.box2_mc._x;
coord.y = box_mc.box2_mc._y;
trace(coord.x);
localToGlobal(coord);
trace(coord.x+" "+coord.y);
But it returns 0 in both cases (before and after globalization). Where's the trick to get the _x and _y of the nested mc?
thank you in advance!
max
View Replies !
View Related
[HELP][AS] LocalToGlobal
HELP!!!
I was working on my stuff on the main page,
set all the X axis and Y axis to those movieCLips which I want them to move around on the main stage, then I decided to make thell all into one single movieClip, so I turned them into one movieClicp which contains all my little moving movieCLips, and all of the sudden, my little movieClips within that one single movieClip start moving around like crazy, that's because the x and y axis was changed to local...
so I tried to turn t hem into the main Stage X and Y axis by using
localToGlobal function...it didn't work out...
there's somthing call "point"
localToGlobal(point);
what is that point?...is that the position which I set in variables?...
how shold I solve this problem?!?!?! in the mean time, I'm still trying...help please...thanks for your time.
View Replies !
View Related
LocalToGlobal HELP
I cant get this thing to work for me...
I have an MC inside another MC. This is the code that I'm using...
By itself, everything works fine. Once i put it inside of another MC, I'm getting in to trouble.
#initclip
_global.CircleClass = function() {
};
// Now make CircleClass a subclass of MovieClip
// This basically allows us to use any MovieClip class methods
CircleClass.prototype = new MovieClip();
//onClipEvent for dots
CircleClass.prototype.onLoad = function() {
this.myYSpeed = 0;
this.myXSpeed = 0;
this.distanceREQ = 30;
this.newY = this._y;
this.newX = this._x;
this.origX = this._x;
this.origY = this._y;
this._x = 200;
this._y = 200;
};
CircleClass.prototype.onEnterFrame = function() {
if ((Math.abs(this.origY-_root._ymouse)<= this.distanceREQ) & (Math.abs(this.origX-_root._xmouse)<=this.distanceREQ)) {
this.newY = Math.floor(_root._ymouse);
this.newX = Math.floor(_root._xmouse);
}
else {
this.newY = this.origY;
this.newX = this.origX;
}
this.myXSpeed = ((this._x-this.newX)/2+this.myXSpeed)/1.2;
this.myYSpeed = ((this._y-this.newY)/2+this.myYSpeed)/1.2;
this._x -= Math.floor(this.myXSpeed);
this._y -= Math.floor(this.myYSpeed);
};
Object.registerClass("myCircle", CircleClass);
#endinitclip
View Replies !
View Related
LocalToGlobal Nightmare
I have been at this for about a day now and am getting quite frustrated with the whole thing. I have a movieClip that is contained inside another clip which I need to get the global coordinates from its local position. I then need to set these coordinates to another movie clip on stage.
This code is all contained on one button on stage...
----------------------------------------------------------
if (pla == 2) {
myobj = new Object();
myobj.x = "_root.top.12._x";
myobj.y = "_root.side.11._y";
localToGlobal(myobj);
setProperty (_root.ball, _x, Number(myobj.x));
setProperty (_root.ball, _y, Number(myobj.y));
gotoAndStop (5);
}
----------------------------------------------------------
Any help would be appreciated.
Thanks,
liamsan
View Replies !
View Related
LocalToGlobal And GlobalToLocal -
Hi... every one.
I have a serious problem. I am scratching my head for the second day...but...can't make it myself. Pls....solutions!!!
I have a mc inside another mc which is again inside another mc.
---------------------------------------
"_root.mainwindow.section.container"
---------------------------------------
Similiarly I also have...
---------------------------------------
"_root.sidewindow.object.box"
---------------------------------------
All I should do is to drag "box" and place on "container"
When I release the "box" I am checking if the _droptarget is "conatainer" or not. If yes then I should place "box" at container's XY position.
I just make it as simple as I could. Actually I have lots of CONTAINERS and lots of BOX. They are all created dynamically using duplicatMovieClip().......
Thanks.
View Replies !
View Related
Localtoglobal/globaltolocal
Hello all
I know there have been many posts on this, but I still seem to be doing something wrong. The file is at:
http://www.the-web-works.co.uk/clien.../test/game.fla
What I am trying to do is this:
1. Create a rectangular MC (the road graphic, _root.board) with an embedded MC (the green square, hidden at the start, _root.board.player) which can be moved by cursor keys (pretty simple).
2. Skew an instance if this MC on the stage to create an isometric 3D appearance, then set the coordinates of another MC (the red cube, _root.cube) to match those of the embedded MC controlled by the user.
The initial positioning of , _root.cube is spot on, but as you move away from the original position, it becomes apparent that it is moving double the distance it should be. You can see the green square (_root.board.player) moving and stopping at the edge of the road as it should, but the coordinates of _root.cube are not mapping precisely to them.
Any thoughts anyone? Many thanks.
Cav
View Replies !
View Related
LocalToGlobal Not Working
hiya,
need to compare the x-coordinates of a couple of mc's which are on completely different timelines/levels. Been using
Code:
point = new Object();
point.x = this._x;
point.y = this._y;
localToGlobal(point);
to find the absolute x co-ord, but doesn't seem to be working. This movieclip is nested inside a couple of others, but shouldnt make a differnece should it
TIA
keef
View Replies !
View Related
LocaltoGlobal Problem
Hi i'm a beginner in actionscript and right now totally stuck with a problem i can identify (localtoglobal problem)but can't solve.
My Main movie is on the timeline (news)
This movie contains 4 other movies of various size (clip1, clip2, theend, lafin).
It seems that those submovies axis are in the middle hence my problem.
My script is inside the main movie (news) and set those movies to absolute coordinates.
You can find the swf wrong result here :
http://www.sangdragons.net/test.swf
And sources here :
http://www.sangdragons.net/test.fla
http://www.sangdragons.net/update.php
Thanks in advance for all the help you can provide.
Klan
View Replies !
View Related
I Too Am Strugling With LocalToGlobal
Hi, I have a MC called crossCirlce. The only thing in it is another MC called crossHair which has the same _x pos as crossHair but a lower _y pos. Then When I rotate the crossCircle MC, the result is that the crossHair MC moves in a circle. Now what When I press SPACE the crosshair stops, moves towards the centre and back out. When I press SPACE again it stops and is removed. At this point I need to get global _x and _y so that I can call a function that checks which part of the stage it finished on. I thought localToGlobal() was the way to go but I only end up getting the same values as the local _x and _y.
Here is the code
// ************************************************** ****
// *** moveToCentre ***
// ************************************************** ****
function moveToCentre () {
// the first time space is pressed rotation stops
// and move to centre begins
// the second time it is pressed throwDart() is called
if (Key.isDown(Key.SPACE) && spacePressed >=2) {
// get x and y pos of crossHair for throwDart function
x = crossCircle.crossHair._x ;
y = crossCircle.crossHair._y ;
// change them to Global values
point = new Object();
point.x = x;
point.y = y;
localToGlobal(point);
dx = point.x;
dy = point.y;
centre = false;
spacePressed = 0;
dartUsed ++;
throwDart();
}
if (crossCircle.crossHair._y >= middle) {
direction = "up";
}
if (crossCircle.crossHair._y <= top) {
direction = "down";
}
if (direction == "down" && rotating == false) {
crossCircle.crossHair._y += (speed/2);
} else if (direction == "up" && rotating == false) {
crossCircle.crossHair._y -= (speed/2);
}
}
and here is the throwDart() function
// ************************************************** ****
// *** throwDart ***
// ************************************************** ****
function throwDart () {
if (dartUsed <=3) {
// remove crossCircle MC
removeMovieClip("crossCircle");
// animate dart towards board
// attach dart MC
attachMovie( "dart", "dart" + dartUsed, 30 + dartUsed );
_root["dart" + dartUsed]._x = dx ;
_root["dart" + dartUsed]._y = dy;
}
}
PS - How do you lot get your code to appear in colour.
View Replies !
View Related
Having Trouble With LocalToGlobal
i just can't get it to work for me. ive checked syntax and everything in my flash 5 bible and the index reference in mx. ive looked for tutes and everything... im just stuck. if someone could explain it to me in laymens terms or gimmie a push in the right direction, i would appreciate it.
View Replies !
View Related
HitTest And LocalToGlobal
Hi everyone,
Does anyone know if hitTest can be used to detect the collision (with shape flag set and co-ords specified) between two clips nested inside a parent?
I've tried using globalToLocal to get the co-ords relative to the stage rather than the parent co-ords system but to no avail.
Any help much appreciated, thanks in advance!
sCam
View Replies !
View Related
Use For GlobalToLocal And LocalToGlobal
Hi there - just doing some reading up on areas I'm not 100% on and I've come across the globalToLocal and localToGlobal methods. I know how they work and have seen examples of code getting the mouse position and converting the coordinates; but I've not seen any good reasons or explanations as to why you would do that?
I know that the coordinates of the _root movie and the MC are different, but can anyone tell me why you would want to convert the coordinates?
thanks
frank
View Replies !
View Related
LocalToGlobal Question
ok, so i have this movie clip "B" within a movie clip "A". i want to be to control the position of "B" but not relative to "A" but to the _root movie. so i was able to write myself code using the localToGlobal function to find out "B"'s coord relative to the _root, but that's not what i want to do. i want to be able to set "B"'s coord to a specific number relative to the _root. how the heck do i do that?
is my problem clear enough?
View Replies !
View Related
LocalToGlobal Mayhem
hi,
i was trying a different approach to "attach" (metaphorically) a mc to another while rotating, using a reference mc (called "node") in the parent mc that points to the position where the child mc must be positioned when the parent is rotated. both mcs (parent -square- and child -rectangle-) are inside a mc called "group".
well, the question is that i'm using localToGlobal to pass the node mc position to the x,y child mc variables. everything works fine until i attach the group mc to another mc (container), and i don't have a clue why it doesn't work in that case. i've checked all the paths in the localToGlobal function but i must be missing something i can't see right now.
here's the code that i'm using (placed in the root timeline):
code:
stop();
//
container.attachMovie("group1", "group", 10);
path = _level0.container.group;
//
vel = 10;
rotate = 0;
point = new Object();
//
this.onEnterFrame = function() {
if (rotate != 0) {
path.square._rotation += rotate;
path.rectangle._rotation += rotate;
// trying to stick the rectangle position to the new square node position
point.x = path.square.node._x;
point.y = path.square.node._y;
path.square.localToGlobal(point);
path.rectangle._x = point.x;
path.rectangle._y = point.y;
}
};
the source is attached below.
why it's not working? thanks in advance.
View Replies !
View Related
Getting LocalToGlobal To Work....
Okay, I've got an action attached to a draggable object's release function, basically the following:
_root["mcShape"+s].onRelease = function(){
stopDrag();
for (x=1;x<=_root.mcDiagram._currentframe;x++){
if (this.hitTest(_root.mcDiagram["hit"+x])){
this.vSnapped = x;
//SNAP
for (p=x*10-9;p<=x*10;p++){
if (_root.mcDiagram["mcSnapPoint"+p].vTaken != 1 && this.vFoundSnapPoint != 1){
_root.mcDiagram["mcSnapPoint"+p].vTaken = 1;
this.vFoundSnapPoint = 1;
trace(this.vFoundSnapPoint);
point = new Object();
point = { x: _root.mcDiagram["mcSnapPoint"+p]._x, y: mcDiagram["mcSnapPoint"+p]._y };
_root.mcDiagram.localToGlobal(point);
this._x = point.x;
this._y = point.y;
}
}
break;
}
else this.vSnapped = 0;
}
if (this.vSnapped == 0){
this._xscale = this.XS;
this._yscale = this.YS;
this._x = this.X;
this._y = this.Y;
}
}
Now, the problem is that the shape snaps to place fine the first time, but if I drag and release it a second time, it doesn't snap....
I've attached a zip file in case the above is confusing. Just look at the actions layer for the commented code.
(I'm using MX2004, btw).
Many thanks :-)
Aragorn23
View Replies !
View Related
LocalToGlobal & HitTest
I need some assistance. I have a nested MC (DragObject_mc) that is being used as a Drag&Drop Object. It is being dropped on another MC (DropArea_mc) which is on the _root level. When the DragObject_mc is
dropped, if it is over the DropArea_mc I want to have it snap to the DropArea's x & y coords.
The problem that I am having is converting the DragObject_mc's x & y coords to the _root level. I am trying to use localToGlobal, but I just can seem to get it right.
Any help is greatly appreciated.
Thanks.
View Replies !
View Related
GlobalToLocal And LocalToGlobal
i don't understand how the globalToLocal and localToGlobal works. i have a movie clip inside a movieclip and i want the movieclip that is inside the movieclip to have the same x's and y's as the stage to make it work and i found the globalToLocal and the localToGlobal actions but have no idea how to make that movieclip have the main movies co-ordinates
View Replies !
View Related
Converting LocaltoGlobal ?
Hi
How to convert local coordinates to global.
Quote:
root.createEmptyMovieClip("rec_mc",1)
rec_mc.attachMovie("cir", "cirNew_mc", 2);
_root.rec_mc.cirNew_mc._x = 200;
_root.rec_mc.cirNew_mc._y = 200;
I have tried this can any one tell how to convert "cirNew_mc" values to global.
Thanks in advance.
View Replies !
View Related
LocalToGlobal() Problem
I can't seem to get localToGlobal to work. Basically, I have a MC (beanMC) on the stage that I'd like to tie to the position of a nested MC (vine1.tip1) .
I am trying to write a function that will tie one mc to another, no matter where it is nested.
Code:
_global.connectMCs = function(mc1, mc2) {
mc1.point = {x:0, y:0};
localToGlobal(mc1.point);
mc2._x = mc1.point.x;
mc2._y = mc1.point.y;
};
connectMCs(vine1.tip1, beanMC);
localToGlobal() doesn't seem to do anything. I have traced the coordinates before and after I call it and they are still {0 , 0}
What am I doing wrong?
View Replies !
View Related
LocalToGlobal Problem
hello ppl, first post here...
I am having trouble with localToGlobal trying to implement some code suggested by a member of another forum.
The general purpose is to detect hits between enemies and fired bullets. As an easy example I made a movie clip named bullet and placed 2 instances on the stage (named bullet1 & bullet2), selected them both and turned them into a containing movie clip called bullets. I did the same thing for enemies, so there were 2 instances of enemy (enemy1 & enemy2) within an enemies movie clip.
I then added the following code to the main timeline:
Code:
for (var i in enemies) {
//loop through all properties of 'enemies' mc. (All individual enemies in the group)
var enemy = enemies[i];
if (!enemy._parent) {
//does not have _parent property, isn't an mc
continue;
//skips this loop
}
for (var j in bullets) {
//loop trough all individual bullets in 'bullets' mc
var bullet = bullets[j];
if (!bullet._parent) {
//does not have _parent property, isn't an mc
continue;
//skips this loop
}
makeGlobal=new Object();
makeGlobal.x=enemy._x;
makeGlobal.y=enemy._y;
localToGlobal(makeGlobal);
trace(makeGlobal.x);
//trace("Enemy X: "+enemy._x);
//trace("Enemy Y: "+enemy._y);
//trace("Bullet X: "+bullet._x);
//trace("Bullet Y: "+bullet._y);
if (enemy.hitTest(bullet._x, bullet._y, true)) {
bullet.removeMovieClip();
trace("*** HIT ***");
//enemy.gotoAndPlay("dead");
}
}
}
It very nearly works, except that the localToGlobal statement isn't doing what it should. The coordinates of makeGlobal are the local ones within the enemies mc.
I'd really appreciate some assistance with this from you actionscript gurus...
View Replies !
View Related
[F8] LocalToGlobal Problem
multiple mcs scaled to 10% in an mc (mcHolder). I need to tell flash that when i click on one of these mc's , that scaled mc will grow to 100% and center to the screen. The problem is not the scaling, but the centering...i am certain that i have to use a localToGlobal call to get this right, but i am not exactly sure how to incoroprate that...anyone up for the challenge of giving me some leads?
View Replies !
View Related
[Help] LocalToGlobal Issue
Hello,
Using Flash 9 with AS3...
This is a quick example of an issue I'm experiencing in a current project. I've used localToGlobal before but never in this situation with MCs within MCs within MCs....
There is a map mc then within the map there are three section mcs. Within each section there is a single unit MC. When you click on the unit mc a property movieclip will open at the mousex and mousey. This is correct... the problem is I want the same thing to happen when you select the unit from the datagrid. The starting coordinates to display the property mc would be the mc.x and mc.y of that unit. I just can't get the localToGlobal portion of the code working.
Below is an image of what the example looks like. The top is when I click on unit 1. The property MC is shown correctly. The second image shows when I selected unit 1 from the datagrid... the window is not anywhere near unit 1 mc.
Any help is appreciated...
Brent
click here to view source FLA
View Replies !
View Related
Actionscript 2.0 LocalToGlobal
whay does this script not work?
var pointo:Object = new Object();
pointo.x = this.menu_mc.menutab_mc._x;
trace("first "+pointo.x);
_root.localToGlobal(pointo);
trace(pointo.x);
I am simply trying to convert the coordinates of a instance from local to global.
View Replies !
View Related
[CS3] LocalToGlobal Error
Hi,
I'm trying to loop through empty movieclips that are encased in another movieclip, so I can determine the x and y coordinates. Therefore, I use the localToGlobal function to determine where the empty movieclips are in relation to the stage. However, I can loop through the movieclips and obtain the local x and y coordinates, but when I use the localToGlobal function I receive an error. The error is "TypeError: Error #1034: Type Coercion failed: cannot convert -240.85000000000002 to flash.geom.Point.
at newcollision_test2_fla::MainTimeline/gameLoop()".
Here is the code:
var point:MovieClip;
for(var i=0; i<hill.perimeter.numChildren-1; i++) { //looping through mcs
point = hill.perimeter.getChildAt(i);
hill.perimeter.localToGlobal(point.x);//the code that errors
}
I'm just wondering how to get rid of the error?
Thank You
View Replies !
View Related
LocalToGlobal Inconsistant?
I have a situation where several clips live in the same parent. All the clips appear visually to be along the top of the parent clip spaced apart from one another horizontally.
When I check (in onPress), the _x and _y for each clip, they all have the same parent and all the same _y value (0).
However, the global (calculated with localToGlobal) _y is different for some of the clips by about 100 pixels.
function onPress() {
if ( Key.isDown(Key.CONTROL) ) {
var pos:Object = { x:0, y:0 };
this.localToGlobal(pos);
trace("Timeslot: " + this._name + ' in global space x: ' + pos.x + ' y: ' + pos.y + ' width: ' + this._width + ' height: ' + this._height );
trace("Timeslot: " + this._name + ' in parent space x: ' + this._x + ' y: ' + this._y);
trace('Timeslot parent: ' + this._parent);
}
Has anyone seen this kind of behaviour before?
Thanks,
Bob
View Replies !
View Related
Problem With LocalToGlobal
Hi guys,
I'll try to explain thi as well as i can. Basically I have an empty movieclip called mcHolder on stage with cordinates x: 179, y:132
I have a movieclip in the library with linkage name mcPanel of height 22 pixels and registration point on the top left hand corner
I then attach 10 instances of mcPanel to mcHolder using the code:
Code:
var yPos:Number = 0;
for(var i:Number = 0; i<10; i++){
mcHolder.attachMovie("mcPanel", "mcPanel"+i, i, {_x:0, _y:yPos});
yPos +=22;
}
All well and good and they attach fine, no problem there.
Now I have a button mcLocal onstage and its onRelease is as follows:
Code:
mcLocal.onRelease = function(){
trace("local y cordinates with respect to mcHolder")
for(var i:Number = 0; i<10; i++){
trace(_root["mcHolder"]["mcPanel"+i]._y);
}
trace("--------------------------");
}
This traces out the following in the output panel:
Code:
local y cordinates with respect to mcHolder
0
22
44
66
88
110
132
154
176
198
--------------------------
This is fine and as expected.
However i now want to output these cordinates with respect to the stage when i click a button with instance name mcStage
Code:
mcStage.onRelease = function() {
trace("y cordinates with respect to Stage");
for (var i:Number = 0; i<10; i++) {
var myPoint:Object = {x:_root["mcHolder"]["mcPanel"+i]._x, y:_root["mcHolder"]["mcPanel"+i]._y};
_root["mcHolder"]["mcPanel"+i].localToGlobal(myPoint);
trace(myPoint.y);
}
trace("--------------------------");
};
However the output is not as expected and I get
Code:
y cordinates with respect to Stage
132
176
220
264
308
352
396
440
484
528
--------------------------
If you notice the first y cordinate is correctly output and is 132. (remember that is the cordinate of the mcHolder movieclip)... However the following cordinates after that seem to be wrong ..instead of y incrementing by 22 pixels ..it seems to be incrementing by 44 pixels...
Any help appeciated as i cant see where im going wrong...
thanks in advance...ive attached the fla as well.... www.experiments.flashmatics.co.uk/test.fla
View Replies !
View Related
_lockroot And LocalToGlobal
I wrote a game that makes use of localToGlobal. Now the client wants to import this game into a presentation tool created in Flash. The games plays within a window in this presentation tool. However, the game fails because the localToGlobal translates the coordinates to the presentation tools root. I thought the _lockroot would solve this problem but it does not. Any ideas ?
Thanks.
View Replies !
View Related
LocalToGlobal/globalToLocal
Hey All,
I'm trying to get my head around the localToGlobal and globalToLocal thing.
What I'm going for is when I click on my box clip on the left side, it should move to the left side of the stage. Which it will. Using the global to local and tweening it based on that. I also wish that when I click the right side of the clip that it should move to the right side of the stage, but instead, it moves about the width of the clip...which makes sense, but not what I want to do.
Code so far:
Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
box.addEventListener(MouseEvent.CLICK, clickHandler);
box.buttonMode=true;
function zoom(what,startSize,endSize,duration){
var spot:Point = what.globalToLocal(new Point(mouseX,mouseY));
var myTweenmX:Tween = new Tween(what,"x",Strong.easeOut,what.x,spot.x,duration,true);
}
function clickHandler(event:MouseEvent):void{
zoom(box,1,3,2)
}
View Replies !
View Related
|