Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-17-2003, 10:20 PM   #1
SundanceKid
Senior Member
 
Join Date: Dec 2002
Posts: 105
Default Smother scrolling.

Hi!
I´m using the MX ScrollPane and added some buttons to jump
too diffrent places in the scrollable background using

scroller.setScrollPosition(700, 0);

My problem is that it moves so stiff and not smoth and nice at all.
It just jump to the direction (700, 0);

Could anyone please help me with this because i´m going
crazy soon.

Thanx a lot.
-Sundance Kid-
SundanceKid is offline   Reply With Quote
Old 03-18-2003, 04:28 AM   #2
Jesse
ActionScript.org Founder
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: New York
Posts: 8,736
Default

As far as I can gather you want to make it so that when you run your command the scrollPane scrolls smoothely to that position rather than just jumping once. Is that correct?
I was surprised to find such a method didn't already exist but it can be made easily enough. Add this code to the Actions layer of the ScrollPane clip (on frame 1, before the #endinticlip):
ActionScript Code:
FScrollPaneClass.prototype.smootheScrollTo = function(x, y) {     if (_global.scrollInt == undefined) {         _global.scrollInt = setInterval(this, "doSmootheScrollTo", 60, x, y);         return true;     } else {         trace (_global.scrollInt)         return false     } }; FScrollPaneClass.prototype.doSmootheScrollTo = function(x, y) {     the_sp = this;     var curScroll = the_sp.getScrollPosition();     var xDiff = curScroll.x-x;     var yDiff = curScroll.y-y;     var nextX = curScroll.x-(xDiff/10);     var nextY = curScroll.y-(yDiff/10);     the_sp.setScrollPosition(nextX, nextY);     if (Math.abs(curScroll.x-x)<=1) {         the_sp.setScrollPosition(x, y);         clearInterval(_global.scrollInt);         delete _global.scrollInt     } };
You call it using:
ActionScript Code:
myScroller_sp.smootheScrollTo(target_x, target_y);
Works very well if I do say so myself (see attached example).
Attached Files
File Type: zip smoothescrollto-v1.zip (13.4 KB, 2456 views)
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.

Last edited by Jesse; 03-18-2003 at 04:59 AM.
Jesse is offline   Reply With Quote
Old 03-18-2003, 04:50 AM   #3
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

wow, that's cool Jesse
didn't think of that before
__________________
â€* GOD Is Near â€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 03-18-2003, 10:13 AM   #4
Charlie_Chalk
Registered User
 
Join Date: Feb 2003
Location: Newcastle - in the GREAT North East
Posts: 17
Default

Hello

I hope it doesn't seem like I'm hyjacking the thread, but I noticed on the HTML example of this code (posted on the home page) you mention that the problem of inertia not stopping quite were you asked it to.

Can you tell me how the code above stops this happening, and can you use this to guarantee the final position of the symbol?

Cheers

CC

Last edited by Charlie_Chalk; 03-18-2003 at 10:25 AM.
Charlie_Chalk is offline   Reply With Quote
Old 03-18-2003, 10:27 AM   #5
Jesse
ActionScript.org Founder
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: New York
Posts: 8,736
Default

Sure. In the second new method outlined above, the conditional statement which applies Math.abs() ensures that the inertia will in fact reach an end point by evaluating when the scroll is within a reasonable (in this case 1px) limit of the target point, shutting off the inertia equation at that point and setting the scroll to its ultimate target explicitly.
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 03-18-2003, 10:30 AM   #6
Jesse
ActionScript.org Founder
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: New York
Posts: 8,736
Default

[self reprimand]I guess, for encapsulation purposes I shouldn't be using a _global scope variable in the code above. Instead the variable should be local to the instance of the scroll pane so multiple scrollpanes can function using these methods simultaneously. Just change all _global references to _parent and that should fix the issue.[/self reprimand]
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 03-18-2003, 11:02 AM   #7
Charlie_Chalk
Registered User
 
Join Date: Feb 2003
Location: Newcastle - in the GREAT North East
Posts: 17
Default

Hello Jesse

Thanks for your explanation, I have attached a .fla that uses Inertia to scroll some text onto the main screen, then via SetInterval the text pauses to be viewed, then alpha fades away.

The final alpha fade is done by replaceing the text with another instance and fading that away. I have done this because I am not sure how to set the original text to fade after the SetInterval.

The reason I ask about the exact positioning of the object after an inertia scroll is because sometimes the second instance of the text (the fading away bit) seems to jump as the inertia didn't finish quite were it was supposed to.

I guess what I'm asking in a very round about way is:

Can you tell me how to set the original text to alpha fade away once its finished moving and has paused for a set time.

or if thats not posibble,

Can you tell me if your positioning code will work in my script (and perhaps give me some clues as to how I apply it?)
Attached Files
File Type: zip actionscript_test.zip (4.4 KB, 1455 views)
Charlie_Chalk is offline   Reply With Quote
Old 03-18-2003, 09:28 PM   #8
Jesse
ActionScript.org Founder
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: New York
Posts: 8,736
Default

Make sure you have embedded the font in the font field. Once that's done your text should alpha fade no problems.
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 03-19-2003, 01:39 AM   #9
funkybudda
Registered User
 
Join Date: Feb 2003
Location: NYC
Posts: 30
Send a message via AIM to funkybudda
Default where to put the code

hi Jesse,

where should I put your code to in the scrollpane components, very new to this component stuff...
funkybudda is offline   Reply With Quote
Old 03-19-2003, 04:04 AM   #10
Jesse
ActionScript.org Founder
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: New York
Posts: 8,736
Default

To be honest I think I'm displayin gmy own ignorance here a little too. The way I did it is as follows:
- Drop a copy of the component on the stage
- Edit that copy (double click it)
- The top Layer is called 'Actions'
- Remove the 'lock' on the Actions label so you can edit it
- Open the action inspector and add my code immediately above the second-last existing line of code which reads "#endinitclip".

Ultimately there hsould be an easier way to do this as my new code just adds two new methods to the class. I tried using an initclip with priority 3 to delay it until after the original class had been instantiated, but no dice, hence this hack way
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:56 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.