Copy link to clipboard
Copied
Hello. My question title is probably termed incorrectly, but basically I want to be able to make my entire scrollpane scrollable/draggable. I'm creating this for tablets, and I want people to be able to click anywhere in the scrollpane and be able to scroll up and down, not just with the little slider. I used the pre-made scrollpane in Flash. Any ideas on how I can do this?
enable the scrollDrag property of your scrollpane. eg, is sp is your scrollpane reference:
sp.scrollDrag=true;
Copy link to clipboard
Copied
enable the scrollDrag property of your scrollpane. eg, is sp is your scrollpane reference:
sp.scrollDrag=true;
Copy link to clipboard
Copied
Thank you!! It worked perfectly.
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Well now I'm having an issue with that. I thought about making a new thread for this problem, but its directly related to this thread's topic, so I'm putting it here.
When I click on a button to go to another frame, I get this error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.containers::ScrollPane/endDrag()
I did some research and found out that this is a common bug and that I have to set the drag property to false. Well, as soon as I did that, everything worked fine with no error. However, now I can't click anywhere on the screen and drag. I can only do that with the scrollbar. Is there a workaround for this bug?
Copy link to clipboard
Copied
from your description, just toggle the scrollDrag property when needed.
Copy link to clipboard
Copied
I need the scrollDrag property whenever someone goes back to the first frame. How would I write that?
Would I write that each time a button is pressed (which takes the user to another frame), the scrollDrag is set to false, like this:
myContent(scrollPane.content).PipeStr_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_PipeStretcher);
function fl_ClickToGoToAndStopAtFrame_PipeStretcher(event:MouseEvent):void
{
gotoAndStop("PipeStretcher");
scrollPane.scrollDrag=false;
}
Will that work and is that what I should do?
Copy link to clipboard
Copied
I read on one thread that this script fixed the bug:
package {
import fl.containers.*;
import flash.events.*;
public class ScrollPain extends ScrollPane {
protected override function endDrag(event:MouseEvent):void {
if (stage) {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
}
}
}
But it didn't work for me. I just got an error saying that package is unexpected.
Copy link to clipboard
Copied
on the first frame:
scrollPane.scrollDrag=true;
if there's a stop() on the first frame, any listener functions that direct the timeline elsewhere should include the following before directing the timeline to another frame:
scrollPane.scrollDrag=false;
Copy link to clipboard
Copied
Thank you so much for your continued help on this.
I do have a stop() on the first frame. So, are you saying it should look something like this:
scrollPane.scrollDrag=true;
stop();
scrollPane.scrollDrag=false;
myContent(scrollPane.content).PipeStr_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_PipeStretcher);
function fl_ClickToGoToAndStopAtFrame_PipeStretcher(event:MouseEvent):void
{
gotoAndStop("PipeStretcher");
}
Does this mean that the scrollpane will be draggable on the first frame but if I click a button inside the movieclip (myContent in the scrollpane (which takes it to another frame), the scrolldrag will be false?
Copy link to clipboard
Copied
no and yes.
use:
scrollPane.scrollDrag=true;
stop();
myContent(scrollPane.content).PipeStr_btn.addEventListener(MouseEvent. CLICK, fl_ClickToGoToAndStopAtFrame_PipeStretcher);
function fl_ClickToGoToAndStopAtFrame_PipeStretcher(event:MouseEvent):void
{
scrollPane.scrollDrag=false;
gotoAndStop("PipeStretcher");
}
Copy link to clipboard
Copied
Thank you. That part works. However, I have a button called Contents that is supposed to take me back to the first frame (label Main) where the scrollpane is. This is my button for that:
Contents_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_Main);
function fl_ClickToGoToAndStopAtFrame_Main(event:MouseEvent):void
{
scrollPane.scrollDrag=true;
gotoAndStop("Main");
}
I've tried it with the scrollPane part in there and without it. Both times I get that error message I received at the beginning of this, that there's a problem with the endDrag.
I don't understand why the scrollpane isn't going back to dragtrue when a user goes back to the first frame.
Copy link to clipboard
Copied
there shouldn't be a scrollDrag line at the point or it should be assigned to false.
Copy link to clipboard
Copied
I've tried both with and without it, true and false. No matter what I try, I always get the error
Error #1009: Cannot access a property or method of a null object reference.
at fl.containers::ScrollPane/endDrag()
Here is all of my code and what I used to test (which still got me the error message above):
scrollPane.scrollDrag=true;
stop();
scrollPane.source = myContent;
scrollPane.setSize(1132.5, 544);
scrollPane.x = 33.8;
scrollPane.y = 174.05;
myContent(scrollPane.content).PipeStr_btn.addEventListener(MouseEvent. CLICK, fl_ClickToGoToAndStopAtFrame_PipeStretcher);
function fl_ClickToGoToAndStopAtFrame_PipeStretcher(event:MouseEvent):void
{
scrollPane.scrollDrag=false;
gotoAndStop("PipeStretcher");
}
myContent(scrollPane.content).SealInst_btn.addEventListener(MouseEvent. CLICK, fl_ClickToGoToAndStopAtFrame_SealInstaller);
function fl_ClickToGoToAndStopAtFrame_SealInstaller(event:MouseEvent):void
{
scrollPane.scrollDrag=false;
gotoAndStop("SealInstaller");
}
Contents_btn.addEventListener(MouseEvent. CLICK, fl_ClickToGoToAndStopAtFrame_1);
function fl_ClickToGoToAndStopAtFrame_1(event:MouseEvent):void
{
gotoAndStop(1);
}
Copy link to clipboard
Copied
then setting the scrollDrag to false does not always prevent the problem.
as a work-around, don't remove your scrollpane. just toggle its visible property when you want it to be visible and not visible.
Copy link to clipboard
Copied
But I really, really appreciate all of your help kglad, as well as your patience. It's good to know that it's not the code that's the problem but the component itself! And I learned more about AS3 through this that I'm sure will help me in the future. Thanks!
Copy link to clipboard
Copied
you're welcome.
(but, i think you mean you saved that file as ScrollPain.as and assigned your component the ScrollPain class.)
Copy link to clipboard
Copied
Well, I finally had to do something somewhat complicated to get it to work, but it did end up working, and if I can get it working, anyone can.
I took out all the false and true scrolldrag code except for the original one that said the scrollpane should have the drag set to true.
Then, I went to File, New and selected ActionScript file (.as). I pasted this code that I found in my hours of searching:
package {
import fl.containers.*;
import flash.events.*;
public class ScrollPain extends ScrollPane {
protected override function endDrag(event:MouseEvent):void {
if (stage) {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
}
}
}
}
Then, I saved it as: ScrollPane.as file. I made sure to save that .as file in the same location as my .fla file.
I went to the scrollpane component in my library, right clicked on it to view the propertis, and changed the Class to ScrollPane. Works fine now.
I thought Adobe would have fixed something this glitchy by now. They could have reworked the inherint AS coding in the scrollpane component and sent it out in one of their update packages.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now