# \[FMX\] Object.watch?

**URL:** <https://forum.kirupa.com/t/fmx-object-watch/30120>\
**Category:** flash\
**Created:** [September 4, 2003, 3:45am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120 "2003-09-04T03:45:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![comicGeek](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@comicGeek](https://forum.kirupa.com/u/comicGeek)\
**Post date:** [September 4, 2003, 3:45am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/1 "2003-09-04T03:45:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 3:54am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/2 "2003-09-04T03:54:57Z")

</div>

[AS]MyTextFieldInstanceName.onChanged = function(){  
//do what you gotta here  
}[/AS]

You can use the onChanged handler for a textfield to determine when the contents of the textfield have changed.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 3:58am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/3 "2003-09-04T03:58:33Z")

</div>

Let me explain. For example I have this script to load external texts:

```auto

_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:

```auto

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:

```auto

_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!

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 3:59am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/4 "2003-09-04T03:59:29Z")

</div>

Sensei, thanks for the reply but I believe that that only works on input textfields! :-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:08am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/5 "2003-09-04T04:08:19Z")

</div>

> \*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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:12am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/6 "2003-09-04T04:12:59Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:22am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/7 "2003-09-04T04:22:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:32am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/8 "2003-09-04T04:32:35Z")

</div>

This is the main script I used:

```auto

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. ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:35am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/9 "2003-09-04T04:35:34Z")

</div>

[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary754.html](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary754.html)

So it would be…

[AS]TextFieldInstanceName.onScroller = function(){  
myScrollbar.resizing();  
}[/AS]

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:39am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/10 "2003-09-04T04:39:33Z")

</div>

Okay I tried adding the script:

```auto

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! :-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:43am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/11 "2003-09-04T04:43:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:44am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/12 "2003-09-04T04:44:37Z")

</div>

Bah… wait, I see…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:50am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/13 "2003-09-04T04:50:40Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 4, 2003, 4:56am UTC](https://forum.kirupa.com/t/fmx-object-watch/30120/14 "2003-09-04T04:56:18Z")

</div>

lol! Thanks anyway sensei! Ponder on this I shall! :beam:
