Hi,
I am loading xml and using Colin Moock’s scrollbar as he desrcibes it in Essential Actionscript 3.0. It all worked fine until I tried to put a link to a jpg inside the xml.
Where other html tags give no problem, the img seems to mess with the textfield height. I gave the textfield a fixed height but when I try to scroll the field with the image, and trace the textfield height, it increases more and more when I scroll down, messing up the scrollbar.
the img tag looks like this (and it loads fine into the textfield):
<IMG ALIGN= "left" SRC='pics/portret.jpg' WIDTH="200" HEIGHT="207" HSPACE='0' VSPACE='10' />
The slightly adapted scrollbar class looks like this (I gave the scrolltrack a fixed height and tried to give t.height a fixed height too within this class but tracing t.height keeps showing that it is increasing while scrolling down):
package {
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.*;
import flash.geom.*;
public class ScrollBar extends Sprite {
private var t:TextField;
private var tHeight:Number;
private var scrollTrack:ScrollTrack;
private var scrollThumb:ScrollThumb;
private var dragging:Boolean = false;
// A flag indicating whether the scrollbar should be redrawn at the next
// scheduled screen update
private var changed:Boolean = false;
private static const SPACING: uint=3;
private var scrollThumbMaxY:Number;
private var scrollThumbY:Number;
private static const SCROLLTRACK_HEIGHT=395;
public function ScrollBar (textfield:TextField,page:uint) {
t = textfield;
tHeight = t.height;
scrollTrack = new ScrollTrack();
addChild(scrollTrack);
scrollThumb = new ScrollThumb();
addChild(scrollThumb);
scrollThumb.buttonMode=true;
t.addEventListener(Event.SCROLL, scrollListener);
scrollThumb.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownListener);
var stageDetector:StageDetector = new StageDetector(this);
stageDetector.addEventListener(StageDetector.ADDED_TO_STAGE,
addedToStageListener);
stageDetector.addEventListener(StageDetector.REMOVED_FROM_STAGE,
removedFromStageListener);
addEventListener(Event.ENTER_FRAME, enterFrameListener);
changed = true;
}
private function addedToStageListener (e:Event):void {
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
}
private function removedFromStageListener (e:Event):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
}
private function enterFrameListener (e:Event):void {
if (t.height != tHeight) {
changed = true;
tHeight = t.height;
if (dragging) {
scrollThumb.stopDrag();
dragging = false;
}
}
if (changed) {
updateScrollbar();
changed = false;
}
}
private function scrollListener (e:Event):void {
if (t.scrollV > t.maxScrollV) {
return;
}
if (!dragging) {
changed = true;
}
}
public function updateScrollbar ():void {
scrollTrack.x = t.x + t.width+SPACING;
scrollTrack.y = t.y;
scrollTrack.height =395;
var numVisibleLines:int = t.bottomScrollV - (t.scrollV-1);
if (numVisibleLines < t.numLines) {
scrollThumb.visible = true;
scrollTrack.visible = true;
scrollThumb.x = t.x + t.width+SPACING-0.6;
scrollThumb.y = t.y + (scrollTrack.height-scrollThumb.height)
* ((t.scrollV-1)/(t.maxScrollV-1));
} else {
scrollThumb.visible = false;
scrollTrack.visible = false;
}
}
public function synchTextToScrollThumb ():void {
scrollThumbMaxY = t.height-scrollThumb.height -15;
scrollThumbY = scrollThumb.y-t.y;
t.scrollV = Math.round(t.maxScrollV
* (scrollThumbY/scrollThumbMaxY));
trace(tHeight);
}
private function mouseDownListener (e:MouseEvent):void {
var bounds:Rectangle = new Rectangle(t.x + t.width+SPACING-0.6,
t.y,
0,
t.height-scrollThumb.height-15);
scrollThumb.startDrag(false, bounds);
//MainMenu.MainMenuRoot._symbolHolder.updatePosition();
dragging = true;
}
private function mouseUpListener (e:MouseEvent):void {
if (dragging) {
synchTextToScrollThumb();
scrollThumb.stopDrag();
//MainMenu.MainMenuRoot._symbolHolder.pauseTweener();
dragging = false;
}
}
private function mouseMoveListener (e:MouseEvent):void {
if (dragging) {
synchTextToScrollThumb();
}
}
}
}
So I think that the code or flash doesn’t handle the img very well, but i could be on the wrong (scroll)track. Getting pretty desperate here , so any iseas are very welcome!
Thanks,
Jerryj.