Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 09-22-2010, 09:24 PM   #1
Senior Member
Join Date: Apr 2007
Posts: 109
Exclamation [AS3] UIScrollBar to Dynamic Textfield


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.
greenpear is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT. The time now is 12:16 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.