Hi,
I'm trying to add a UIScrollbar to dynamically created textfields but i'm getting weird 'flashing' results.
I'm creating my textfields in a class like so:
ActionScript Code:
public class NewsPost extends Sprite
{
public var newsBody:TextField;
public function NewsPost(body:String)
{
newsBody = new TextField();
newsBody.embedFonts = true;
newsBody.multiline = true;
newsBody.wordWrap = true;
newsBody.autoSize = TextFieldAutoSize.LEFT;
newsBody.antiAliasType = AntiAliasType.ADVANCED;
newsBody.styleSheet = IStyleSheet(Gaia.api.getPage("index").assets.stylesheet).style;
newsBody.htmlText = body;
addChild(newsBody);
// Positions & Sizing
newsBody.x = 90;
newsBody.y = newsTitle.height + 10;
newsBody.width = 350;
}
}
Then the following loads news from xml into the body textfields, then sorts them into columns.. allowing me to scroll horizontally.
ActionScript Code:
var posts:Array = [];
var lastY:Number = 0;
var columnHeight:Number = 440;
var column:DisplayObjectContainer = new Sprite();
sectionpage.containerMC.newsMC.addChild(column);
sectionpage.columns = [];
sectionpage.columns.push(column);
for (var i:int = 0; i<myXML.news.length(); i++)
{
var body:String = myXML.news.newsBody[i];
var newsPost:NewsPost = new NewsPost(body);
posts.push(newsPost);
if (lastY + newsPost.height > columnHeight)
{
var nextX:Number = column.x + column.width;
column = new MovieClip();
column.x = 600;
sectionpage.columns.push(column);
sectionpage.containerMC.newsMC.addChild(column);
column.y = 0;
lastY = 0;
}
column.addChild(newsPost);
newsPost.y = lastY;
lastY += newsPost.height + 40;
}
Now if there is too much text, i need a scrollbar to showup...
Can anyone advise where i need to insert the code?
I have this :
ActionScript Code:
var scrollBar:UIScrollBar = new UIScrollBar();
scrollBar.scrollTarget = newsBody;
scrollBar.height = newsBody.height;
scrollBar.move(newsBody.x + newsBody.width, newsBody.y);
addChild(scrollBar);
function updateScrollBar():void{
scrollBar.update();
if (scrollBar.enabled == false) {
scrollBar.alpha = 0;
} else {
scrollBar.alpha = 100;
}
}
I've tried inserting it into the NewsPost class but this gives me a weird flashy bug.
Can anyone advise?
many thanks.