0
votes

I was watching a youtube tutorial about as3,I tried to copy the code to see how it works, but even though it worked for the guy in the video, it didn't work for me..

Video Link(update): https://www.youtube.com/watch?v=pKj1IgWJd-A&ab_channel=WaarithAbdul-Majeed

(short post update)I made this late at night and didn't really include a lot of stuff in the post about the problem, so pretty much the movie clip is supposed to follow the mouse but it doesn't even though I made the code for it.

The errors are about circle.x = content.mouseX; circle.y = content.mouseY;

Flash keeps popping up "1120: Access of undefined property content."

Code:

addEventListener(Event.ENTER_FRAME,shipgo);

function shipgo(e:Event){

    ship_b.x=mouseX;
    ship_b.y=mouseY;
    
    }
1
Could you add more detail as to what you're trying to accomplish? It seems like you want a ship to follow the mouse but that won't happen since an Event.ENTER_FRAME fires only once. You can instead use a MouseEvent.MOUSE_MOVE listener on the ship's display parent to update its position to the mouse's position when the mouse position changes within the parent's dimensions. - ugotopia123
The "didn't work" description is far to vague for a problem. The script looks absolutely fine and should work as long as you re-created its environment correctly. Like, publish for AS3 rather than AS1/2, have a child of current context named ship_b that is visible, maybe something else. - Organis
Hi, use the edit option to update your question with more details. What Youtube video link? What does "didn't work" actually mean? - VC.One
@VC.One I updated the post with the vid link, also by "doesn't work" I meant it the code doesn't change anything, the movie clip just remains static when it's supposed to follow the mouse. - SithNinja59
Where is content error coming from? Do you have such code for using its MouseX/Y? It's confusing... Do you want to fix circle.x = content.mouseX or you want to fix ship_b.x=mouseX;? Update your post with actual vars you want to move and we will try to help you. - VC.One

1 Answers

0
votes

Try referencing the stage for its mouse coordinates:

stage.addEventListener( Event.ENTER_FRAME, shipgo );

function shipgo ( e:Event ) :void
{
    ship_b.x = stage.mouseX;
    ship_b.y = stage.mouseY;
}