Ciao a tutti, avrei bisogno di usare questo codice che mi gestisce lo scroll dinamico di un campo di testo con contenuto esterno.
Questo codice è nato per flash 5, ma io avrei bisogno di pubblicarlo per Flash 7 in maniera da poter caricare anche le jpg all'interno del campo di testo (tramite i tag html), ma se lo pubblico in flash7 avvengono degli errori, ad esempio scrollando usando le freccette ("arrowup", "arrowdown") non si muove la barretta ("scrollbar").
Qualcuno sa dirmi dove sono i codici incompatibili o deprecated o chissa cosa?a livello intuitivo credo sia qks relativa all'oggetto "Text", che con Flash7 assume nuovi e più complessi significati... ma non saprei proprio!
Vi ringrazio molto, ciao!!
onClipEvent (load){
//---------------------------------------------------------------------------------------
//--initialze variables
numLines = 18; // guesstimate of number of visible lines in text area
tolerance = 1; // controls how close the scroll bar can get before snapping to target
speed = 5; // controls re-size and re-position animation speed
origHeight = scrollbar._height;
origX = (scrollbar._x + 1);
text = "windows OS scroll bar...";
//---------------------------------------------------------------------------------------
//--resizes scrollbar according to content length
function scrollResize(){
lastHeight = scrollbar._yscale;
totalLines = (text.maxscroll - 1) + numLines;
newHeight = 100 * (numLines) / totalLines;
scaleDiff = Math.abs(newHeight - lastHeight);
currentPosition = scrollbar._y;
pixelDiff = currentPosition - (arrowUp._height - 1);
}
//---------------------------------------------------------------------------------------
//--positions scrollbar when text is scrolled
function scrollPosition (){
scrollbar._y = (lineHeight * (text.scroll - 1)) + (arrowUp._height - 1);
}
}
//-------------------------------------------------------------------------------------------
onClipEvent (enterFrame){
scrollResize();
//---------------------------------------------------------------------------------------
//--animate the scale and position of scrollbar if resize is required
if (lastHeight <> newHeight){
if (scaleDiff < tolerance && scaleDiff > (0 - tolerance)){
scrollbar._yscale = newHeight;
heightDiff = origHeight - scrollbar._height;
lineHeight = HeightDiff/(text.maxscroll - 1);
rePosition = false;
text.scroll = 1;
scrollPosition();
}else{
if (newHeight < lastHeight){
scrollbar._yscale = scrollbar._yscale - (scaleDiff / speed);
}else if (newHeight > lastHeight){
scrollbar._yscale = scrollbar._yscale + (scaleDiff / speed);
}
}
}
if (rePosition == true){
currentPosition = currentPosition - (pixelDiff / speed);
scrollbar._y = currentPosition;
pixelDiff = pixelDiff - (pixelDiff / speed);
if (currentPosition == (arrowUp._height - 1)){
rePosition = false;
}
}
//---------------------------------------------------------------------------------------
//--scrolling when arrows are pressed
if (startScroll == true){
if (scroll == "up" && text.scroll > 1){
text.scroll--;
scrollPosition();
}
if (scroll == "down" && text.scroll < text.maxscroll){
text.scroll++;
scrollPosition();
}
}
//---------------------------------------------------------------------------------------
//--page text if mouse is clicked within the scrollarea
if (paging == true){
if (hitLocation < scrollbar._y){
text.scroll-=numLines;
scrollPosition();
if (hitLocation >= scrollbar._y && hitLocation <= (scrollbar._y + scrollbar._height)){
paging = false;
}
}else{
text.scroll+=numLines;
scrollPosition();
if (hitLocation >= scrollbar._y && hitLocation <= (scrollbar._y + scrollbar._height)){
paging = false;
}
}
}
// test = (arrowDown._y - arrownDown._height) - scrollbar._height;
}
//--------------------------------------------------------------------------------------------
onClipEvent (mouseDown){
//--detect if mouse click is in scrollarea but not on scrollbar
if (scrollArea.hitTest(_root._xmouse, _root._ymouse) and not scrollbar.hitTest(_root._xmouse, _root._ymouse)){
hitLocation = this._ymouse;
paging = true;
resize = false;
}
//--detect if mouse click is on up arrow button
if (arrowUp.hitTest(_root._xmouse, _root._ymouse)){
scroll = "up";
startScroll = true;
arrowUp.gotoAndPlay(2);
resize = false;
}
//--detect if mouse click is on down arrow button
if (arrowDown.hitTest(_root._xmouse, _root._ymouse)){
scroll = "down";
startScroll = true;
arrowDown.gotoAndPlay(2);
resize = false;
}
//--detect if mouse click is on scrollbar
if (scrollbar.hitTest(_root._xmouse, _root._ymouse)){
startDrag (scrollbar, false, origX, arrowUp._height - 1, origX, heightDiff + (arrowUp._height - 1));
scroll = "scrollbar";
scrollbar.gotoAndPlay(2);
resize = false;
}
}
//--------------------------------------------------------------------------------------------
//--reset scroll properties when mouse button is released
onClipEvent (mouseUp){
scroll = "";
startScroll = false;
paging = false;
stopDrag();
resize = true;
scrollbar.gotoAndStop(1);
arrowUp.gotoAndStop(1);
arrowDown.gotoAndStop(1);
}
//--------------------------------------------------------------------------------------------
//-adjust text when scroll bar is dragged
onClipEvent (mouseMove){
if (scroll == "scrollbar"){
text.scroll = Math.round((scrollbar._y - arrowUp._height)/lineHeight + 1);
//--test for scrollbar position to correct errors created by numLines guesstimate
if (scrollbar._y == Math.ceil(arrowDown._y - (arrowDown._height - 1) - scrollbar._height)){
text.scroll = text.maxscroll;
}
}
updateAfterEvent();
}
//--------------------------------------------------------------------------------------------
//--detects when content is text box is changed...reset scroll property and resize scroll bar
onClipEvent (data){
rePosition = true;
scrollResize();
text.scroll = 1;
}