Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Custome scrollbar for a dynamic textfield

New Here ,
Nov 02, 2009 Nov 02, 2009

I have searched the internet and these forums for a easy to understand way to make a custome scroll bar for my dynamic text boxes. However I cannot find any, and this the code I have:


Var scrollupper:Number =  ;
var scrolllower:Number=  ;

var textlower:Number= ;
var textupper:Number=  ;

var scrollRange:Number= scrolllower-scrollupper;
var textRange:Number= textlower-textupper;

function scrol() {
var moved:Number = Scroller_mc._y - scrollupper;
var pctMoved:Number = moved/scrollRange;
Var textmove:Number= pctMoved*textRange;
textMain_mc._y=textlower-textmove;
}

scroller_mc.OnPress= function() {
this.startDrag(falsh,this._x,scrollupper,this._x,scrolllower);
this.onMouseMove=scroll;
}

scroller_mc.OnRelease = scroller_mc.OnReleaseOutside = function() {
this.stopDrag();
this.onMouseMove = null;
}

If anyone can help me, that would be great.

TOPICS
ActionScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2009 Nov 03, 2009

That code is AS2, so you either need to repost in the AS2 forum.  If you want to pursue an AS3 solution, try seraching Google for "AS3 custom scrollbar" and you will find some tutorials

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 03, 2009 Nov 03, 2009

Ok I found a tutorial that I can use, http://www.flashessential.com/archives/17 . However it does not tell me what code to write to make it work with a dynamic text that is driven by XML files, or am I missing something?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2009 Nov 03, 2009

The line of code that assigns...  myText.text = ....

You will end up assigning it whatever xml text you parse from your xml file.

When you are going thru that tutorial try to really understand the mechanics of what they are doing to control the scrollbars.  If you can get that understood, you will find it easier to manipulate things if you need to tweak anything.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 03, 2009 Nov 03, 2009

I understand what the code is doing. However I do not have the knowlege to get the code to retreive the text from the xml file and then run the rest of the code.  The reason I want to do this is because I want to update the website with out going into the flash file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 03, 2009 Nov 03, 2009

I GOT IT, I had to use that tutorial I have posted and added this section to the code:

var xmlholder:URLLoader=new URLLoader(new URLRequest("test.xml"));

xmlholder.addEventListener(Event.COMPLETE,onload);

function onload(e:Event):void {
    myText.text="";
    var xml:XML=new XML(xmlholder.data);
    for (var i:Number=0; i<xml.story.length(); i++) {
        myText.appendText(xml.story.body+"\n\n");
    }
};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 03, 2009 Nov 03, 2009

Ok now I have  new problem with the custom scrollbar, the scroll face (the bar that moves) does not want to go the full lenght of the scroll bar's background. When it does the text stops scrolling.  Also if you let go of the scroll face then it will move up the the scroll bar by itself.  I have a zip with all the files.

Also note that I cannot get the color code to work. So it is commented out.

If anyone could help that would be great.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 04, 2009 Nov 04, 2009
LATEST

This is the problem, the math for the scroller limits have to be changed to fit the full length of scroller background.


var bounds:Rectangle = new Rectangle(slider_mc.x,slider_mc.y,0,206);
var dragging:Boolean = false;
function dragSlider(event:MouseEvent):void
{
slider_mc.startDrag(false,bounds);
dragging = true;
}
function dropSlider(event:MouseEvent):void
{
slider_mc.stopDrag();
dragging = false;
}

function checkSlider(event:Event):void
{
myText.scrollV = Math.round ((slider_mc.y - bounds.y)* myText.maxScrollV/206)
}
stage.addEventListener(Event.ENTER_FRAME, checkSlider);
function textScrolled(event:Event):void
{
slider_mc.y = bounds.y + (myText.scrollV * 206/myText.maxScrollV);
}
myText.addEventListener(Event.SCROLL, textScrolled);

Now I have not fixed the color problem but I am sure I fix it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines