I am making a Scrollbar component and I want a script to call a calculation function for resizing the scrollbar when a new data is loaded. I was experimenting with Object.watch but it’s use is beyond me. I don’t understand if its the thing I need.
Can Object.watch call a function when say a dynamic textfield’s data is changed?
Now inside my scrollbar is a function, resizing(), that handles the resizing relative to the amount of text the textfield is displaying. Currently I used the following to call the resizing() function inside the scrollbar. First I gave the scrollbar component an instance name:
This, of course, worked. But the thing is I want to contain the checking and everything that is related to the scrollbar inside the scrollbar. Having to call the resizing() function outside the scrollbar is such a lame and lousy method. So I experimented on Object.watch. Can someone please advice me on how to go about this? Thanks!
*Originally posted by comicGeek *
**Sensei, thanks for the reply but I believe that that only works on input textfields! :-\ **
Yes you are right, but I posted before you explained what you wanted in full
As for Object.watch, I think that is just to see if any actionscript changed, so I don’t think that will work here. I will see if I can come up with something, but i’m not sure too. You may have to stick with your current method.
lol! Thanks sensei! I can probably solve this problem by using enterFrame but that would much lamer than the method I’m currently using. I hope I can find a way for this.
What method are you using to adjust your scrollbar size? If it goes by the amount you can scroll you can use the onScroller handler. It gets nvoked when the scroll, maxscroll, hscroll, maxhscroll, or bottomscroll property of a text field changes.
Legend:
scrollBar is the instance name of my scrollbar’s scrollbar. trackBar is the instance name of my scrollbar’s track bar and targetMC is the variable for the targeted textfield.
I don’t really know about the onScroller handler.
And everytime the scroll, maxscroll, hscroll, maxhscroll, or bottomscroll property of a text field changes (in your case you use the maxscroll and scroll properties) the resizing() function will be called for the scrollbar.
Apparently it successfully called the resizing function but it continually calls it and thus it ended up unscrollable cause everytime you scroll it recalculates! :-\
Don’t run it onEnterFrame, just have it on a frame like a normal dynamic event handler.
As a quick example…
[As]this.createTextField(“tf”, 1, 100, 100, 100, 75);
tf.border = true;
tf.text = “asdf”;
tf.onScroller = function() {
trace(“MORE!”);
};
this.onMouseDown = function() {
tf.text = “t
t
t
t
t
t
”;
};[/AS]
It creates a textfield with the instance name “tf”, then sets the original text as “asdf” then when you press themouse down on the stage it resets the text to a bunch of "t"s that are seperated by a line break.
Since the onChanged is not in the onEnterFrame it only gets run once when you change the text.
I think your safest bet is adjusting it when you load in the new text like you were doing in the first place.
It may be “lame” (although I don’t think so), it still works, and I can’t currently think of another method besides running a function onEnterFrame (which would be less efficient then calling the function when you load new text in)