PDA

View Full Version : Problem with scrollBar



Snivvle
December 3rd, 2009, 05:44 PM
Here is the dilemma, I think I need a second pair of eyes. Thats it! :thumb:


Seriously though, I have an issue with the scrollBar. It works fine, but when I come back to the frame, it literally shoots me an error message.

Imagine using just 2 frames. On frame 1, I have the following code:

var scrollBar:UIScrollBar = new UIScrollBar();
//Create the scrollBar instance
scrollBar.scrollTarget = displayTextBox;
//make the height the same as the textfield
scrollBar.height = displayTextBox.height;
//Move the scrollbar to the righthand side
scrollBar.move(displayTextBox.x + displayTextBox.width - 14, displayTextBox.y);
//add it to the stage
addChild(scrollBar);

Now on that frame 1, I have a textField with the name "displayTextBox". So basically, I am just attaching the scrollBar to this textField. Imagine now, on Frame 1 a button that allows you to goto frame 2. So, you goto frame 2, and there is a button to go back to frame 1. So you click to go back to frame 1. Now, flash doesn't recognize the textField "displayTextBox" any longer, and sees it as a NULL object. What is the deal with that?

If I remove the "addChild(scrollBar)", going back and forth is fine, and I am able to "trace (displayTextBox)" which tells me that it is indeed a textField. When I attach the scrollBar, and try to "trace (displayTextBox)" after going from frame 1, to frame 2, and then back to frame 1; it tells me that the "displayTextBox" is NULL.

I am losing my mind, and have a feeling this is going to be a simple fix, but again I need that second pair of eyes :luigi:

Thanks!

creatify
December 3rd, 2009, 06:30 PM
is there code on frame two that is modifying that textField, or does it just not exist on that frame?

I used your code to set up an example, and everything works fine for me, but I added a couple items that your's appeared to be missing.

Fla is two big, but see attached image for frame set up.

frame 1:


import fl.controls.UIScrollBar;

stop();

var str:String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus condimentum tortor ut ipsum. Fusce nec nibh id libero rhoncus ullamcorper. Morbi at justo sit amet ante porta tempor. Vestibulum sollicitudin consequat mi. Praesent pulvinar, turpis quis consequat varius, felis turpis ullamcorper mauris, ut aliquet tortor lacus ac nibh. Aenean sodales, felis eu porta congue, nisi mauris accumsan odio, id sagittis purus libero at mauris. Fusce odio arcu, auctor non, imperdiet rhoncus, dapibus id, ante. Nullam risus justo, interdum quis, tristique quis, dapibus sit amet, lacus. Praesent vel neque non magna auctor lacinia. Phasellus faucibus. Nulla leo. Suspendisse imperdiet ultricies tellus. Sed sit amet felis. Nullam ipsum. Maecenas at est quis magna consequat sodales. Aliquam nulla quam, consectetur mollis, gravida et, pretium sagittis, est. Sed tortor. Aliquam condimentum congue velit. Etiam condimentum orci vel purus. Vivamus convallis. Fusce in eros at ante aliquet tincidunt. Sed ornare sollicitudin ante. Praesent augue est, faucibus ut, ornare ac, tempus vel, ligula. Ut scelerisque ultrices nibh. Sed in lacus ac nibh viverra molestie. Nunc aliquam leo sodales nunc. Nunc erat augue, rutrum ut, porttitor id, laoreet ut, est. Donec viverra malesuada justo. Duis dictum dui eu justo. Praesent ultricies turpis vitae libero. In id purus. Aliquam iaculis nulla vel nulla. In ullamcorper, diam ut pretium facilisis, sapien nisi pellentesque nibh, sit amet accumsan risus metus eget lorem. Morbi turpis. Phasellus nulla lacus, semper vel, tristique sed, fermentum at, eros. Nullam in lacus pulvinar justo adipiscing tempus. Mauris consectetur commodo metus.";


displayTextBox.text = str;


var scrollBar:UIScrollBar = new UIScrollBar();
//Create the scrollBar instance
scrollBar.scrollTarget = displayTextBox;
//make the height the same as the textfield
scrollBar.height = displayTextBox.height;
//Move the scrollbar to the righthand side
scrollBar.move(displayTextBox.x + displayTextBox.width - 14, displayTextBox.y);
//add it to the stage
addChild(scrollBar);

var boo:Boolean = true;


if(!_btn.hasEventListener(MouseEvent.MOUSE_DOWN)) {
_btn.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
}

function onDown(e:MouseEvent):void {
boo = !boo;
trace("boo: "+boo)
if(!boo) {
// remove the scrollBar as you'll just be stacking them each time you return to frame 1
removeChild(scrollBar);
scrollBar = null;
gotoAndStop(2);
} else {
gotoAndStop(1);
}
}


frame 2;


stop();

Snivvle
December 3rd, 2009, 07:51 PM
There is no code modifying that textField, that's what is weird. I have a few textFields on frame 1, and the only one having issues is the one with a scrollBar attached to it. It simply becomes NULL. The plot thickens!

Snivvle
December 3rd, 2009, 10:14 PM
Got it resolved by simply removing child of the scrollbar before going to the next frame. Sometimes the biggest headaches are caused by the simplest of problems.:trout: Thanks for the help.

creatify
December 4th, 2009, 08:03 PM
glad to help