Post edited 1:26 am – February 6, 2010 by Inter-Reality
Post edited 1:28 am – February 6, 2010 by Inter-Reality
Dark Vortex,
your solution:
on your main stage:
- create a scrollbar movieclip and give it an instance name of dtf_scroller
- set the registration of all the scrollbar elements to top left.
- in the scrollbar movieclip you may want to create some elements but the formost is the slider. (to make things pretty you may want to add a scrollbar and an up and down button but for this explanation its the raw deal.)
- give your slider an instancename of slider_mc.
- create a dynamic textfield and give this an instance name of : dtf (dynamic text field).
- add a new layer on the timeline in your main stage. rename the layer to AS
- add the following script to the timeline:
//dynamic scroll visibilty test
//author: Inter-Reality.nl
var maxH:Number = 260;
//dtf definitions
var myFormat:TextFormat = new TextFormat();
myFormat.font = “Arial”;
myFormat.color = 0×333333;
myFormat.size = 24;
dtf.wordWrap = true;
dtf.multiline = true;
dtf.setTextFormat(myFormat);
dtf.height = maxH;
dtf.text = “all dynamic text goes here…”;
//if you fill this up till the text surpases your dtf.height the scrollbar will appear
dtf_scroller.visible = dtf.maxScrollV > 1;
dtf.addEventListener(Event.CHANGE, function():void{
dtf_scroller.visible = dtf.maxScrollV > 1;
});
stage.addEventListener(Event.ENTER_FRAME, checkSlider);
//dtf_scroller.scrollUP_mc.addEventListener(MouseEvent.CLICK, upScroll);
//dtf_scroller.scrollDown_mc.addEventListener(MouseEvent.CLICK, downScroll);
dtf_scroller.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragSlider);
stage.addEventListener(MouseEvent.MOUSE_UP, dropSlider);
function upScroll(event:MouseEvent):void
{
trace(dtf.scrollV);
dtf.scrollV -= 1;
}
function downScroll(event:MouseEvent):void
{
trace(dtf.scrollV);
dtf.scrollV += 1;
}
var bounds:Rectangle = new Rectangle(dtf_scroller.slider_mc.x, dtf_scroller.slider_mc.y,0,maxH);
var dragging:Boolean = false;
function dragSlider(event:MouseEvent):void
{
dtf_scroller.slider_mc.startDrag(false,bounds);
dragging = true;
}
function dropSlider(event:MouseEvent):void
{
dtf_scroller.slider_mc.stopDrag();
dragging = false;
}
function checkSlider(event:Event):void
{
//if(dragging){trace(“scroll”);}
dtf.scrollV = Math.round ((dtf_scroller.slider_mc.y – bounds.y)* dtf.maxScrollV/70);
}
function textScrolled(event:Event):void
{
dtf_scroller.slider_mc.y = bounds.y + (dtf.scrollV * 70/dtf.maxScrollV);
}
dtf.addEventListener(Event.SCROLL, textScrolled);
To mention: this is a script that doesn't fail. I just tested it and its a dirty way of making a scrollbar visible or non visible.
Let me know if you can work with this…
oh yeah! to spice it up you could chose to use tween elements for positioning…gives a nice effect…
Happy coding!
[adjustment]
added a zip file dtf.zip