Mouse Movement

  • routhu
  • Beginner
  • Beginner
  • User avatar
  • Posts: 47
  • Loc: India

Post 3+ Months Ago

Hi all,

I am using this code for vertical xml scrolling gallery. How to add the X and Y Positions For Mouse up and Down for the Below code.

Code: [ Select ]
if (_global.chk == undefined) {
_global.chk = 1;
}

mask_y = getProperty("_root.main.verti.mask", _y);
mask_h = getProperty("_root.main.verti.mask", _height);
roller_y = getProperty("_root.main.verti.roller", _y);
roller_h = getProperty("_root.main.verti.roller", _height);

if (_global.chk == 1) {
if ((roller_y+roller_h)>(mask_y+mask_h)) {
setProperty("_root.main.verti.roller", _y, getProperty("_root.main.verti.roller", _y)-3);
} else {
_global.chk = 2;
}

} else if(_global.chk == 2) {
if (roller_y<=mask_h) {
setProperty("_root.main.verti.roller", _y, getProperty("_root.main.verti.roller", _y)+3);
} else {
_global.chk = 1;
}
}
  1. if (_global.chk == undefined) {
  2. _global.chk = 1;
  3. }
  4. mask_y = getProperty("_root.main.verti.mask", _y);
  5. mask_h = getProperty("_root.main.verti.mask", _height);
  6. roller_y = getProperty("_root.main.verti.roller", _y);
  7. roller_h = getProperty("_root.main.verti.roller", _height);
  8. if (_global.chk == 1) {
  9. if ((roller_y+roller_h)>(mask_y+mask_h)) {
  10. setProperty("_root.main.verti.roller", _y, getProperty("_root.main.verti.roller", _y)-3);
  11. } else {
  12. _global.chk = 2;
  13. }
  14. } else if(_global.chk == 2) {
  15. if (roller_y<=mask_h) {
  16. setProperty("_root.main.verti.roller", _y, getProperty("_root.main.verti.roller", _y)+3);
  17. } else {
  18. _global.chk = 1;
  19. }
  20. }


Thanks
krishna
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

what exactly you mean by add the X and Y Positions For Mouse up and Down?
you want to scroll on mouse down and stop on mouse up?
  • routhu
  • Beginner
  • Beginner
  • User avatar
  • Posts: 47
  • Loc: India

Post 3+ Months Ago

Hi IceCold,

I am having the script which is scrolling by default. But What i need is That has to scroll whenever i move mouse over that one and that has to move up and down based on the mouse movement, Consider center of page as reference for mouse up and down.

Can you please help me to sort this problem.

Thanks
Krish
  • routhu
  • Beginner
  • Beginner
  • User avatar
  • Posts: 47
  • Loc: India

Post 3+ Months Ago

Any one Please....?
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

hmm, so your code moves the gallery up and down, up and down, up and down :P
well, to move it on mouse position you have to consider the mouse position, don't you?
For the following code to work, you need to position
movieclip verti to be at coordinates 0,0 inside movie clip main (top left).
and movieclip mask to be at coordinates 0, 0 in movieclip verti
and the shape from movieclip mask to be at coordinates 0, 0 as well.
You can also add some code to position the roller at mask_y or at mask_height, if roller scrolls a bit more up or down, but that's your task to do.

Code: [ Select ]
this.onEnterFrame = function()
{
    mask_y = _root.main.verti.mask._y;
    mask_h = _root.main.verti.mask._height;
    mask_middle = (mask_y + mask_h) / 2; // take middle of mask as reference
    
    roller_y = _root.main.verti.roller._y;
    roller_h = _root.main.verti.roller._height;
    ymouse = _root.main.verti.mask._ymouse;
    
    // if mous out of range
    if (ymouse < mask_y || ymouse> mask_y + mask_h)
        speed = 0;
    else
        speed = (ymouse - mask_middle)/ 10;
    // calculate speed -> the closer to middle-> slower, closer to edges-> faster


    // if roller bottom reaches mask bottom and scroll up, stop
    if ((roller_y+roller_h)<(mask_y+mask_h) && speed < 0)
        speed = 0;
    // if roller top reaches mask top and scroll down, stop
    if (roller_y > mask_y && speed > 0)
        speed = 0;
    _root.main.verti.roller._y += speed;
}
stop();
  1. this.onEnterFrame = function()
  2. {
  3.     mask_y = _root.main.verti.mask._y;
  4.     mask_h = _root.main.verti.mask._height;
  5.     mask_middle = (mask_y + mask_h) / 2; // take middle of mask as reference
  6.     
  7.     roller_y = _root.main.verti.roller._y;
  8.     roller_h = _root.main.verti.roller._height;
  9.     ymouse = _root.main.verti.mask._ymouse;
  10.     
  11.     // if mous out of range
  12.     if (ymouse < mask_y || ymouse> mask_y + mask_h)
  13.         speed = 0;
  14.     else
  15.         speed = (ymouse - mask_middle)/ 10;
  16.     // calculate speed -> the closer to middle-> slower, closer to edges-> faster
  17.     // if roller bottom reaches mask bottom and scroll up, stop
  18.     if ((roller_y+roller_h)<(mask_y+mask_h) && speed < 0)
  19.         speed = 0;
  20.     // if roller top reaches mask top and scroll down, stop
  21.     if (roller_y > mask_y && speed > 0)
  22.         speed = 0;
  23.     _root.main.verti.roller._y += speed;
  24. }
  25. stop();
  • routhu
  • Beginner
  • Beginner
  • User avatar
  • Posts: 47
  • Loc: India

Post 3+ Months Ago

HI IceCold,

THANKS A LOT

your code is working as per my need.
  • routhu
  • Beginner
  • Beginner
  • User avatar
  • Posts: 47
  • Loc: India

Post 3+ Months Ago

HI IceCold,

THANKS A LOT,

One more help for me . previously your code is for if the mouse will move up the scoller will move up and vice versa. now i want the reverse . if it move up , then the scoller come down and if it move down , then the scoller move up.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

oh man, just use your mind.
If negative speed it scrolls up, if positive speed it scrolls down.
Now figure it out what exactly should be changed. A sign maybe?
  • routhu
  • Beginner
  • Beginner
  • User avatar
  • Posts: 47
  • Loc: India

Post 3+ Months Ago

Hi IceCold,

It will little bit confused , i will tried lot of times but i didn't get the solution. So please tell me the solution if possible.

Thanks
  • routhu
  • Beginner
  • Beginner
  • User avatar
  • Posts: 47
  • Loc: India

Post 3+ Months Ago

Hi IceCold,

i also used below code, it will work fine but its working for only fixed images. I am calling images through XML code. So need to dynamic. Please look at the code and give me the proper solution..,


Code: [ Select ]
var centerY:Number = 100;
var distanceFraction = 2;
onMouseMove = function()
{
  _root.main.roller.endY = centerY - ((_ymouse - centerY) + distanceFraction);
}
_root.main.roller.onEnterFrame = function()
{
  this._y += (this.endY - this._y) / 10;
}
Mouse.addListener(this);
stop();
  1. var centerY:Number = 100;
  2. var distanceFraction = 2;
  3. onMouseMove = function()
  4. {
  5.   _root.main.roller.endY = centerY - ((_ymouse - centerY) + distanceFraction);
  6. }
  7. _root.main.roller.onEnterFrame = function()
  8. {
  9.   this._y += (this.endY - this._y) / 10;
  10. }
  11. Mouse.addListener(this);
  12. stop();


Thanks
Krishna
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

honestly, i have no idea ... since i don't know how you load your images and how you place them on stage.
  • sarahe11e
  • Born
  • Born
  • sarahe11e
  • Posts: 1

Post 3+ Months Ago

hello. I was searching for a way to have the mouse control navigation in a Flash file that sounds similar to your 'gallery' mentioned above. I wondered if you resolved and if you might offer assistance. I am a true novice, but can show you what I've accomplished so far in ActionScript 2 if you are interested/have the time.
  • zorrcell
  • Newbie
  • Newbie
  • zorrcell
  • Posts: 8

Post 3+ Months Ago

for a mouse to control navigation? hers how u do it
(too lazy to write the code and sicne ur such a novince u can do it urself)
get the stage width

divide it by 2

the mouse position FROM the center (width divide by two) will control the speed of which the navigation moves

that is how you make your nagivation move by the mouse
if you want the accual navigation, thes such a thing called GOOGLE
i did a similar search a year ago and i found 100 examples

Post Information

  • Total Posts in this topic: 13 posts
  • Users browsing this forum: No registered users and 15 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.