ForumsProgramming ForumAS3 Help Pleaaassee *tears hair out*

8 4094
kingryan
offline
kingryan
4,196 posts
Farmer

So I was looking at this tutorial and tried copying and pasting out the code from the bottom to make the arrow point to where the mouse is.

HOWEVER! The initial code didn't work by itself and after using Google to sort out a fair few of my errors I became stuck with a problem in my first line of code:

onEnterFrame=function();

Which keeps giving me errors, which I fix like this:

onEnterFramefunction.(); and onEnterFrame.function.(); and many other variations thanks to Google and finding how to fix errors...

So is there anyone out there on AG who knows how to simply fix this problem of mine?

  • 8 Replies
kingryan
offline
kingryan
4,196 posts
Farmer

By the way, this is the entire code.

import flash.display.
onEnterFramefunction();
{
xdist=_xmouse-arrow._x;
ydist=arrow._y-_ymouse;
angle=Math.atan(xdist/ydist)*(180/Math.PI);
if(_ymouse>arrow._y)
{
angle+=180;
}
if(_ymouse<arrow._y && _xmouse<arrow._x)
{
angle+=360;
}
if(_ymouse==arrow._y && _xmouse<arrow._x)
{
angle+=360;
}
arrow._rotation=angle;
}
Darkroot
offline
Darkroot
2,763 posts
Peasant

....... This is actionscript 2 code.....

Trying making a AS2 flash file and putting it in there. It should of been obvious with the error saying "migration issues"

This is one of the many reason you don't copy and paste code. That you don't understand because it won't get you anywhere.

Darkroot
offline
Darkroot
2,763 posts
Peasant

Oh and I've found one of my old actionscript 3 examples. You have to give the movie clip a left-middle registration point and don't forget the instance name of the movie clip.

arrow.x = stage.stageWidth /2;
arrow.y = stage.stageHeight /2;

addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);

function onLoop(evt:Event):void {
arrow.rotation = getAngle(arrow.x, arrow.y, mouseX, mouseY);
}

function getAngle(x1:Number, y1:Number, x2:Number, y2:Number): Number{
var radians:Number = Math.atan2(y2-y1, x2-x1);
return rad2deg(radians);
}

function rad2deg(rad:Number):Number {
return rad * (180 / Math.PI);
}

Either from Learning actionscript 3 book or essential actionscript 3
Hectichermit
offline
Hectichermit
1,828 posts
Bard

why didn't you just download the file, you probably lost some stuff by just copy and pasting the code...probably the Movie clip instance name like Dark root mentioned...

kingryan
offline
kingryan
4,196 posts
Farmer

This is one of the many reason you don't copy and paste code. That you don't understand because it won't get you anywhere.


Well I don't understand when I try to learn it anyway...so I take snippets of code and learn through that. I read through the whole page anyway and understood that bit...

Well I'll try doing it in an AS2 file later...

Thanks.
Darkroot
offline
Darkroot
2,763 posts
Peasant

Well I don't understand when I try to learn it anyway..

This is probably caused by you learning actionscript 3 and 2 at the same time. I would recommend finding a tutorial site or another learning medium and sticking with that site and actionscript version. I would also recommend you forget trig and learn the basic or actionscript. You cannot hope to be successful if you don't know the basics.

I also would like to mention that page doesn't teach actionscript it assumes you know it.

kingryan
offline
kingryan
4,196 posts
Farmer

Yes I know!

Just so you know I'm just playing around in Flash because it is fun...and I like a challenge...

Thanks for all your help and suggestions.

Darkroot
offline
Darkroot
2,763 posts
Peasant

I your really determined to learn flash I would recommend you get the Learning actioscript 3 book. It a fantastic book that doesn't assume you have any previous knowledge of programming and it isn't very expensive. There is also this site that has many other resources including free ones.

Showing 1-8 of 8