简体   繁体   中英

XY restrictions for custom mouse cursor in Actionscript3

I have this interactive 5 seconds animated intro for a website. the preloader and one item are animating and i made the second animation follow the mouse cursor but it has to stay within a certain part of the stage to work with the other animation happening on screen.

I have this code on the movie clip

Mouse.hide();

potistiri.addEventListener(Event.ENTER_FRAME, newCursor);

function newCursor(event:Event): void { potistiri.x = mouseX; potistiri.y = mouseY; }

and i like i said i just want it to stay in the area i want...

i found this code which gives me errors for not putting the staments if and else if correctly or that it needs a rightparen when i input my numbers in...

if(this._x>Stage.width){

this._x=Stage.width;

}else if(this._x<0){

this._x=0; }

but i cant get it to work... i need it to move between x 208-656 and y 140-336 and when it gets out of that area the object stay there doing its loop and you see the normal mouse cursor moving in the rest of the screen.

thanks a lot in advance...im leaving my it to the experts in here to pls help me ouy!

The logic you're using in your if/else is fine for clamping the movie clip to a specific area, what exactly do your errors say?

In regards to seeing the normal mouse cursor again you could try using the same if/else checks to determine whether the mouse should or should not be hidden ie if the mouse is outside the area and is hidden, call Mouse.show(), else if it is inside the area and shown, call Mouse.hide().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM