-
How to rotate an arrow with mouse drag????
this attached to 1st frame on stage:
arrow_mc.onMouseMove = function() {
var adjacent:Number = _xmouse-arrow_mc._x;
var opposite:Number = _ymouse-arrow_mc._y;
var radians:Number = Math.atan2(opposite, adjacent);
arrow_mc._rotation = radians*180/Math.PI;
};
with an "Arrow object" mc on stage called: arrow_mc
How this code can be enhanced so that the arrow can be rotated by dragging the arrow from its pointer, or tail.
thanks!
-
Client Software Programmer
I just made this, try it let me know.
PHP Code:
arrow_mc.onPress = function(){
saved_x = _xmouse;
saved_y = _ymouse;
onEnterFrame = function(){
if(_xmouse < saved_x){
arrow_mc._rotation -= 5;
}
if(_xmouse > saved_x){
arrow_mc._rotation += 5;
}
}
}
arrow_mc.onRelease = arrow_mc.onReleaseOutside = function(){
delete onEnterFrame;
}
-
Alloy Bacon, thank you!
this is really a good code to start with. thanks again!
-
.
Hi,
PHP Code:
arrow_mc.onMouseDown = function()
{
this.onMouseMove = function()
{
if (this.hitTest(_root._xmouse, _root._ymouse, true))
{
myRadians = Math.atan2(_root._ymouse - this._y, _root._xmouse - this._x);
myDegrees = Math.round((myRadians * 180 / Math.PI));
this._rotation = myDegrees + 90;
arrow_mc._rotation = this._rotation;
}
};
};
arrow_mc.onMouseUp = function()
{
if (this.onMouseMove)
{
delete this.onMouseMove;
}
};
-
Thank you fruitbeard, what a good improvement to the original code!
Just one more question, how this code could be utilized, if several arrows are attached from the library to stage, off course each with different instance name.
-
.
Hi,
without going too into depth, you can just alter the var names like so.
PHP Code:
arrow_mc1.onMouseDown = function() { this.onMouseMove = function() { if (this.hitTest(_root._xmouse, _root._ymouse, true)) { myRadians1 = Math.atan2(_root._ymouse - this._y, _root._xmouse - this._x); myDegrees1 = Math.round((myRadians1 * 180 / Math.PI)); this._rotation = myDegrees1 + 90; arrow_mc1._rotation = this._rotation; } }; };
arrow_mc1.onMouseUp = function() { if (this.onMouseMove) { delete this.onMouseMove; } };
arrow_mc2.onMouseDown = function() { this.onMouseMove = function() { if (this.hitTest(_root._xmouse, _root._ymouse, true)) { myRadians2 = Math.atan2(_root._ymouse - this._y, _root._xmouse - this._x); myDegrees2 = Math.round((myRadians2 * 180 / Math.PI)); this._rotation = myDegrees2 + 90; arrow_mc2._rotation = this._rotation; } }; };
arrow_mc2.onMouseUp = function() { if (this.onMouseMove) { delete this.onMouseMove; } };
as I say, this is just quickly done, but you could use arrays and make them both use the same functions, I will leave that to you.
-
Ok, thank you, will give try and post it here.
All the best!
-
.
Hi,
PHP Code:
var clips:Array = new Array(arrow_mc1, arrow_mc2, arrow_mc3);
for (var i:Number = 0; i < clips.length; i++)
{
var toeNail:MovieClip = clips[i];
toeNail.onMouseDown = function()
{
this.onMouseMove = function()
{
if (this.hitTest(_root._xmouse, _root._ymouse, true))
{
this.radians = Math.atan2(_root._ymouse - this._y, _root._xmouse - this._x);
this.degrees = Math.round((this.radians * 180 / Math.PI));
this._rotation = this.degrees + 90;
}
};
};
toeNail.onMouseUp = function()
{
if (this.onMouseMove)
{
delete this.onMouseMove;
}
};
}
-
.
Hi,
I got timed out, so new post.
PHP Code:
var i:Number;
var barrs:Array = new Array(bar1, bar2, bar3);
var texts:Array = new Array(outPut1, outPut2, outPut3);
var clips:Array = new Array(arrow_mc1, arrow_mc2, arrow_mc3);
for (i = 0; i < clips.length; i++) { var thisText:TextField = TextField(texts[i]); thisText.text = "0";
var thisBar:MovieClip = MovieClip(barrs[i]); thisBar._width = 0;
var toeNail:MovieClip = MovieClip(clips[i]);
toeNail.identity = i;
toeNail.onRollOver = function() { this.useHandCursor = true; };
toeNail.onMouseDown = function() { this.onMouseMove = function() { if (this.hitTest(_root._xmouse, _root._ymouse, true)) { this.radians = Math.atan2(_root._ymouse - this._y, _root._xmouse - this._x); this.degrees = Math.round((this.radians * 180 / Math.PI)); this._rotation = this.degrees + 90; this._rotation = this._rotation; this.showAngle = this._rotation; if (this.showAngle < 0) { this.showAngle = this.showAngle + 360; } texts[this.identity].text = String(this.showAngle); barrs[this.identity]._width = 100 / 360 * this.showAngle; } }; };
toeNail.onMouseUp = function() { if (this.onMouseMove) { delete this.onMouseMove; } }; }
Last edited by fruitbeard; 05-31-2015 at 06:45 AM.
-
fruitbeard, thank you for finding the time to help!
going through all the codes in this thread, came with the following:
this allow you to drag, and rotate it.
first, create mc "Arrow_mc" and inside it a child mc called "drage".
//Create a button on stage, and put the following code inside it.
on (press) {
var i = _root.getNextHighestDepth();
_root.attachMovie("Arrow_mc", "Arrow_mc"+i, i, {_x:100, _y:100});
var mcArrow:MovieClip = MovieClip(eval("Arrow_mc"+i));
}
//Put the following code in frame 1 on stage:
_root.onEnterFrame = function() {
//
mcArrow.onPress = function() {
if (this.drag.hitTest(_root._xmouse, _root._ymouse, true)) {
this.startDrag();
} else {
this.onMouseMove = function() {
this.radians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
this.degrees = Math.round((this.radians*180/Math.PI));
this._rotation = this.degrees;
};
}
};
mcArrow.onMouseUp = function() {
this.stopDrag();
if (this.onMouseMove) {
delete this.onMouseMove;
}
};
};
-
.
Hi,
Well done, you don't need the onEnterFrame at all, infact it's just a waste of resources.
-
hi,
You still need to use "onEnterFrame", just test the code.
regards!
-
.
-
Could you, if possible, please re-upload the file for an old version of flash (Flash pro 8.0) or post the code here. Thanks!
Last edited by Dr_flash; 06-02-2015 at 02:00 PM.
-
.
HI,
Sorry, unable to, CS6 here, perhaps you csn download the trial version.
or attach yoru *.fla and we can paste the code here
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|