View Full Version : [FMX] Object.watch?
comicGeek
September 3rd, 2003, 11:45 PM
Hello all,
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?
lostinbeta
September 3rd, 2003, 11:54 PM
MyTextFieldInstanceName.onChanged = function(){
//do what you gotta here
}
You can use the onChanged handler for a textfield to determine when the contents of the textfield have changed.
comicGeek
September 3rd, 2003, 11:58 PM
Let me explain. For example I have this script to load external texts:
_global.test = new LoadVars();
test.load("test.txt");
test.onLoad = function() {
tf.html = true;
tf.htmlText = this.testing;
};
and also a script to load new data on the same textfield when I press on a button:
on(release){
_global.test = new LoadVars();
test.load("test2.txt");
test.onLoad = function() {
tf.html = true;
tf.htmlText = this.testing;
};
}
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:
_global.test = new LoadVars();
test.load("test.txt");
test.onLoad = function() {
tf.html = true;
tf.htmlText = this.testing;
myScrollbar.resizing();
};
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!
:)
comicGeek
September 3rd, 2003, 11:59 PM
Sensei, thanks for the reply but I believe that that only works on input textfields! :-\
lostinbeta
September 4th, 2003, 12:08 AM
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.
comicGeek
September 4th, 2003, 12:12 AM
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. :)
lostinbeta
September 4th, 2003, 12:22 AM
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.
comicGeek
September 4th, 2003, 12:32 AM
This is the main script I used:
scrollBar.onEnterFrame = function() {
scrAmt = Math.round((scrollBar._y-trackBar._y)/((trackbar._height-scrollBar._height)/targetMC.maxscroll));
targetMC.scroll = scrAmt;
};
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. :(
lostinbeta
September 4th, 2003, 12:35 AM
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary754.html
So it would be...
TextFieldInstanceName.onScroller = function(){
myScrollbar.resizing();
}
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.
In theory, i've never actually used it
comicGeek
September 4th, 2003, 12:39 AM
Okay I tried adding the script:
targetMC.onScroller = function() {
scrolling();
};
Apparently it successfully called the resizing function but it continually calls it and thus it ended up unscrollable cause everytime you scroll it recalculates! :-\
lostinbeta
September 4th, 2003, 12:43 AM
Don't run it onEnterFrame, just have it on a frame like a normal dynamic event handler.
As a quick example...
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\nt\nt\nt\nt\nt\n";
};
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.
lostinbeta
September 4th, 2003, 12:44 AM
Bah... wait, I see.....
lostinbeta
September 4th, 2003, 12:50 AM
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)
comicGeek
September 4th, 2003, 12:56 AM
lol! Thanks anyway sensei! Ponder on this I shall! :beam:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.