I am searching the web for a good working vertical scroll in Flash and don't seem to find a good solution. I will use it for the product page layout with all the images. So I suppose it means no text scroll but an MC scroll.
My main design issue is that I would like a user to be able to scroll it with the mouse whell (same way like frames in HTML).
I don't like than the entire site layout scrolls up, I would much rather designate a section in the site layout where the info can be scrolled. This way the logo of the site and all the main navigation on the top will always be visible.
Main issue is that I can not find a scroll which would work on mouse wheel scroll, a user is always have to grab the bar or click on the up/down arrows in order for the scroll to work.
Is it possible to make a scroll work on a mouse wheel in flash?
Try ScrollPane component. It's basically a MovieClip container with vertical and horizontal Scrollbars attached. You can assign it content using source property. After manipulating source, you should call update() method to update scrollbars to new content.
It scrolls on wheel event by default. Just make sure to have mouse over the component - that's the default behaviour. Take a look at my example: http://dev.flashlabs.eu/examples/scroll-pane/
You can download the source and take a look: http://dev.flashlabs.eu/examples/scroll-pane/source.zip
Hi Peter,
I started to have a problem once I started to change the content of "MyContent". What I did I combined all the product images mc's (which act as buttons as well) into one mc named "MyContent"
As soon as I did that the scroll pane treats "MyContent" as a very, very long mc and repositiones it half way to the left of the scroll pane.
I need to accomplish to things.
One is to make sure that the position of the "MyContent" is exactly where I want. Its upper left corner has to be in the same position as upper left corner of the scroll pane. Now it seems that the top is properly aligned, but the center of "MyContent" mc is aligned with the left margin of the scroll pane.
Two is make sure that scroll bar of the scroll pane recognizes the true height of the "MyContent" mc.
mc_pane2.source = MyContent;
mc_pane2.horizontalScrollPolicy = "off";
mc_pane2.update();
stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
function mouseWheelHandler(event:MouseEvent):void {
mc_pane2.verticalScrollPosition -= event.delta;
}
In update() method, ScrollPane measures total width and total height of its content. The content should have its orientation points set to TOP_LEFT. If you have some graphics occasionally reaching further left, you should mask your content so it doesn't reach out of its intended bounds. Also, it's important to have your content at its full size when you do the update() call because it is being measured then. If your content only starts to animate in in this time, you'll get unexpected results unless you create some solid (transparent) backgound of intended size for your content MovieClip.
Peter,
Thanks for keeping up the correspondence.
I noticed something new happening with my site in the section where I have applied your code for the scroll pane.
My entire site is set to be scaled to fit on screen, however in the section where I used your code for scroll pane it is suddenly jumps to its ture 100% scale.
I understand it is because of the lines:
import flash.display.StageScaleMode;
stage.scaleMode = StageScaleMode.NO_SCALE;
Can I block them out, or only the last one? Are they imperative for your code to work?
Here is how the code is presently looks like:
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
stage.scaleMode = StageScaleMode.NO_SCALE;
mc_pane2.source = MyContent;
mc_pane2.horizontalScrollPolicy = "off";
mc_pane2.update();
stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
function mouseWheelHandler(event:MouseEvent):void {
mc_pane2.verticalScrollPosition -= event.delta;
}
Thank you, I appreciate that you follow up on my questions.
I did not expect that a seemingly simple implementation of a scroll pane
will bring so many additional questions.
FYI, Maybe you will find it interesting or useful in the future.
I was not able to access the mc inside the scroll pane with the code:
TweenLite.to(mc_pane2.content.scrollpaneBckgrnd_mc.FloraLytell_btn, 1,
);
I had to explicitly specify that it is the mc I am accessing inside the
scroll pane, otherwise I was getting errors:
TweenLite.to(MovieClip(mc_pane2.content).scrollpaneBckgrnd_mc.FloraLyt ell_btn,
1, );
P.S. If you have time can you briefly tell me why is there a line of code
in your sample:
mc_pane2.update();
Can it be changed with the size specified for the mc_pane2:
mc_pane2.setSize(556, 300);
what would be the major difference between them?
I was not able to access the mc inside the scroll pane with the code:
TweenLite.to(mc_pane2.content.scrollpaneBckgrnd_mc.FloraLytell_btn, 1,
);
I had to explicitly specify that it is the mc I am accessing inside the
scroll pane, otherwise I was getting errors:
TweenLite.to(MovieClip(mc_pane2.content).scrollpaneBckgrnd_mc.FloraLyt ell_btn,
1, );
That's OK. It's because ScrollPane::content is of a type DisplayObject. DisplayObject does not contain property named scrollpaneBckgrnd. MovieClip, however, is a dynamic class and enables you to (try to) access virtually any property you can imagine. If it doesn't exist in your particular instance of a MovieClip, you'll get an runtime error.
P.S. If you have time can you briefly tell me why is there a line of code
in your sample:
mc_pane2.update();
ScrollPane::update() measures your content and sets scrollbars accordingly, if needed.
Can it be changed with the size specified for the mc_pane2:
mc_pane2.setSize(556, 300);
what would be the major difference between them?
They definitelly don't do the same. ScrollPane::setSize() sets size of your scrollpane
If you get same results using one or the other function, it's because your content is smaller than 556x300px and you don't need scrollbars so in this particular case ScrollPane::update() would "do nothing".
North America
Europe, Middle East and Africa
Asia Pacific