dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: moock scrollbar and images in textfield

  1. #1
    Senior Member
    Join Date
    Nov 2004
    Location
    Amsterdam
    Posts
    212

    moock scrollbar and images in textfield

    Hi,

    I am using the scrollbar that Colin Moock wrote in his Essential Actionscript 3.0. It worked fine sofar, but now I ran into a problem. I am loading the text from xml. In that xml I also want to use a link to a jpg, using html code like:
    Code:
    <img align= "left" src='pics/portret.jpg'   hspace='0' vspace='0' />
    This has always worked fine for me (in as 2.0), and this time the jpg loads into the textField alright, but then the scrollbar isn't working properly anymore, from the moment on you try to scroll.

    scrollBar code:
    Code:
    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 var _page:uint;
    	private var symbol:String;
       
        public function ScrollBar (textfield:TextField,page:uint) {
    		 t = textfield;
    		 tHeight = t.height;
    		_page=page;
    		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 = t.height-15;
    
          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));
    		
        }
    
        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();
    		
          }
        }
      }
    }
    What visually happens is that I can't scroll 'past' the jpg, the scrollthumb gets kinda stuck there.

    The weird thing is that when I try to scroll past the jpeg, or when I go to a line dynamically using scrollV, the height of the textfield increases, while it is a fixed height (no autoSize). That is the problem I guess.

    Any ideas would be very welcome,

    thanks,

    Jerryj.
    Last edited by jerryjj; 11-30-2007 at 11:18 AM. Reason: insufficient info

  2. #2
    Senior Member
    Join Date
    Nov 2004
    Location
    Amsterdam
    Posts
    212
    Still not working, but i changed the scrolltrack height to a fixed height and the t.height too. Still t.height blows up when t.scrollV increases (and so did the scrolltrach.height, but not anymore now).

  3. #3
    Senior Member
    Join Date
    Nov 2004
    Location
    Amsterdam
    Posts
    212
    t.height increases when I trace it, not visually.

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I think this is a problem since some time. You will also not see any images when you use the textarea. You probably need to use a MovieClip scroller, where the textfield is in the MovieClip.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Senior Member
    Join Date
    Nov 2004
    Location
    Amsterdam
    Posts
    212
    thanks; actually I do see the image, but it seems to mess with the textField height property.

    Arghh

  6. #6
    Senior Member
    Join Date
    Nov 2004
    Location
    Amsterdam
    Posts
    212
    Is this a known bug in fp9 or as3.0? I used to do this a lot. Has anyone loaded images into a textfield, and managed to scroll it too? Please let me know,

    thanks,

    Jerryj.

  7. #7
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    This was already the case in Flash 7 and 8 and has not changed.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  8. #8
    Senior Member
    Join Date
    Nov 2004
    Location
    Amsterdam
    Posts
    212
    I used this technique a lot in 7 and 8 and it alway worked, for instance http://www.traxngigz.nl/

  9. #9
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    The problem is always when the image is the last thing to show. May be I mixed up with the textarea, since I remember it does not seem to work there.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center