eludethedude
02-24-2008, 11:43 AM
Hey guys.
I have a job on which has a deadline for Monday, so any fast help on this is much appreciated.
Firstly I will mention that my knowledge on action scripting is limited so I try and make the most of available resources,
I am using the following code which is perfect for what I want, well, almost:
/*
################################################## #################################
Be sure to modify the name and path to your text field if you use this code in another
movie. My text field is at the _root level, named "myText_txt"
The instance of the scroll mechanism is named "scroller_mc" - make SURE you name the
instance, and that you make the necessary adjustments if you rename it.
Locate the scrollModule_mc movie clip in the Library and refer to additional code
in that timeline Note that you can modify the height and width of the track_mc and
thumb_mc to fit your text field. The code should accomodate so long as the instances
are named.
This demo .fla should be in a folder along with three text files named "longText",
"medText" and "smText". If they are missing, nothing will show up in the text field!
################################################## #################################
*/
//declare a persistent reference to _root
_global.mainTL = this;
//boolean variable used to shut off dynamic thumb positioning if thumb is doing the scrolling;
//set initially to false. See the onScroller callback at bottom of page to observe how it's used
var usingThumb = false;
//start with scroll mechanism invisible
//it will appear only when necessary
scroller_mc._visible = false;
//create LoadVars object
readText = new LoadVars ();
/*define callback for when text loads
namely: fill the dynamic text field with the content of the external file
and initialize three things:
- be sure the text field starts at the first line (scroll = 0);
- be sure the scroll thumb is at the top of its track (_y = 0);
- modify the thumb's _yscale proportional to the quantity of text
*/
readText.onLoad = function () {
//declare contents of text field
myText_txt.htmlText = this.myText;
//disable scroll mechanism if it's not needed
if (myText_txt.maxscroll < 2) {
scroller_mc._visible = false;
} else {
scroller_mc._visible = true;
}
//initialize text field's scroll property
myText_txt.scroll = 0;
//initialize scrollbar thumb's position
scroller_mc.thumb_mc._y = 0;
//set variable which is ratio of total text to what's visible
var percentVisible = (myText_txt._height / myText_txt.textHeight) * 100;
//use this variable to modify _yscale of scrollbar thumb
scroller_mc.thumb_mc._yscale = percentVisible;
};
/*for testing, define three different text files with different amounts of content
three buttons load the files to test response of scroll mechanism
you don't need this if you're not loading different text files into the textfield
*/
short_mc.onRelease = function () {
readText.load ("smText.txt");
};
medium_mc.onRelease = function () {
readText.load ("medText.txt");
};
long_mc.onRelease = function () {
readText.load ("longText.txt");
};
/*
onScroller is an event in Flash MX which is called when any property related to
scroll in the targeted textfield changes. I use it here to vary the _y property
of the scrollbar thumb based on the scroll property of the text field
*/
myText_txt.onScroller = function () {
//check to be sure scrolling is being done with arrows instead of the thumb
if (!usingThumb) {
//find the usable length of travel, which is the height of the track minus the height of the thumb
var trackLength = scroller_mc.track_mc._height - scroller_mc.thumb_mc._height;
//find where the textfield scroll is
var scrollPos = (this.scroll - 1) / (this.maxscroll - 1);
//finally, set _y property of thumb
scroller_mc.thumb_mc._y = trackLength * scrollPos;
}
};
As you can see I’m using a scrolling textbox reading 3 external files from the click of 3 simple buttons:
short_mc
medium_mc
long_mc
If I keep the buttons in "scene 1" along with the textbox all works as intended, my problem is I want the buttons within an animation/movie clip, ie "scene 1 > symbol 56 > tween 9".
If I keep the script in "scene 1" and move the buttons to "tween 9" what changes must I make to the original script to keep it working??
Sorry to sound so nubish, I’ve already created the project and wish to add this as a final feature.
Thanks in advance guys
Steve
I have a job on which has a deadline for Monday, so any fast help on this is much appreciated.
Firstly I will mention that my knowledge on action scripting is limited so I try and make the most of available resources,
I am using the following code which is perfect for what I want, well, almost:
/*
################################################## #################################
Be sure to modify the name and path to your text field if you use this code in another
movie. My text field is at the _root level, named "myText_txt"
The instance of the scroll mechanism is named "scroller_mc" - make SURE you name the
instance, and that you make the necessary adjustments if you rename it.
Locate the scrollModule_mc movie clip in the Library and refer to additional code
in that timeline Note that you can modify the height and width of the track_mc and
thumb_mc to fit your text field. The code should accomodate so long as the instances
are named.
This demo .fla should be in a folder along with three text files named "longText",
"medText" and "smText". If they are missing, nothing will show up in the text field!
################################################## #################################
*/
//declare a persistent reference to _root
_global.mainTL = this;
//boolean variable used to shut off dynamic thumb positioning if thumb is doing the scrolling;
//set initially to false. See the onScroller callback at bottom of page to observe how it's used
var usingThumb = false;
//start with scroll mechanism invisible
//it will appear only when necessary
scroller_mc._visible = false;
//create LoadVars object
readText = new LoadVars ();
/*define callback for when text loads
namely: fill the dynamic text field with the content of the external file
and initialize three things:
- be sure the text field starts at the first line (scroll = 0);
- be sure the scroll thumb is at the top of its track (_y = 0);
- modify the thumb's _yscale proportional to the quantity of text
*/
readText.onLoad = function () {
//declare contents of text field
myText_txt.htmlText = this.myText;
//disable scroll mechanism if it's not needed
if (myText_txt.maxscroll < 2) {
scroller_mc._visible = false;
} else {
scroller_mc._visible = true;
}
//initialize text field's scroll property
myText_txt.scroll = 0;
//initialize scrollbar thumb's position
scroller_mc.thumb_mc._y = 0;
//set variable which is ratio of total text to what's visible
var percentVisible = (myText_txt._height / myText_txt.textHeight) * 100;
//use this variable to modify _yscale of scrollbar thumb
scroller_mc.thumb_mc._yscale = percentVisible;
};
/*for testing, define three different text files with different amounts of content
three buttons load the files to test response of scroll mechanism
you don't need this if you're not loading different text files into the textfield
*/
short_mc.onRelease = function () {
readText.load ("smText.txt");
};
medium_mc.onRelease = function () {
readText.load ("medText.txt");
};
long_mc.onRelease = function () {
readText.load ("longText.txt");
};
/*
onScroller is an event in Flash MX which is called when any property related to
scroll in the targeted textfield changes. I use it here to vary the _y property
of the scrollbar thumb based on the scroll property of the text field
*/
myText_txt.onScroller = function () {
//check to be sure scrolling is being done with arrows instead of the thumb
if (!usingThumb) {
//find the usable length of travel, which is the height of the track minus the height of the thumb
var trackLength = scroller_mc.track_mc._height - scroller_mc.thumb_mc._height;
//find where the textfield scroll is
var scrollPos = (this.scroll - 1) / (this.maxscroll - 1);
//finally, set _y property of thumb
scroller_mc.thumb_mc._y = trackLength * scrollPos;
}
};
As you can see I’m using a scrolling textbox reading 3 external files from the click of 3 simple buttons:
short_mc
medium_mc
long_mc
If I keep the buttons in "scene 1" along with the textbox all works as intended, my problem is I want the buttons within an animation/movie clip, ie "scene 1 > symbol 56 > tween 9".
If I keep the script in "scene 1" and move the buttons to "tween 9" what changes must I make to the original script to keep it working??
Sorry to sound so nubish, I’ve already created the project and wish to add this as a final feature.
Thanks in advance guys
Steve