Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-24-2006, 08:01 PM   #1
MCB
Registered User
 
Join Date: Jan 2005
Posts: 4
Default Help with code:

I am working in MX 2004 with scrollable dynamic text. Everything works great and fast until I apply a component that allows me to fully justify my text. The longer the scrollable text is the worst it gets.

The text does get fully justified but my scrollbar which was very fast before that action, becomes very slow and bumpy and the last four lines of the text do not show up. I do not know how to fix it and I would really appreciate it if anyone can take a look at it and let me know what they see wrong.

This is the code in my component. I thank you in advance for your help

MC
Attach Code

#initclip

function blocktext(){
this.MIN_WORD_DISTANCE=this.MIN_WORD_DISTANCE || 0.1;
this.MAX_LINE_TOLERANCE=this.MAX_LINE_TOLERANCE || 1.0;
this.MAX_SQUEEZE_WORDS=this.MAX_SQUEEZE_WORDS || 3;
this.ALLOW_SQUEEZE=this.ALLOW_SQUEEZE || true;
this.scrollPosition = 0;
}

var o=blocktext.prototype=new MovieClip();

Object.registerClass("blocktext",blocktext);

o.setTargetTextfield=function(textfield, scrollbar){
this._y=textfield._y;
this._x=textfield._x;
textfield._visible=false;
if (scrollbar!=null){
this.scrollbar = scrollbar;
scrollbar._visible = false;
scrollbar.addEventListener("scroll",this);
}
var newFormat=textfield.getTextFormat();
if (newFormat.size==null || newFormat.font==null) {
trace("ERROR: TextFormat non-consistant - use only one format for the whole text.");
return false;
}
this.textFormat=newFormat;
this.sourceTextfield=textfield;
this.minSpace=newFormat.size*this.MIN_WORD_DISTANC E;

//Calculate Line height
this.createTextField("test",0,0,0,0,0);
this.test.autoSize="left";
this.test.setNewTextFormat(newFormat);
this.test.text="a";
var h1= this.test._height;
this.test.text="a\na";
this.lineHeight=this.test._height-h1;
this.test.text="";


var paragraphs=textfield.text.split("\r");
if (paragraphs.length==null) return;
this.words=[];
for (var i=0;i<paragraphs.length;i++){
this.words[i]=paragraphs[i].split(" ");
}

this.setSize(textfield._width,textfield._height);

}

o.scroll = function()
{
this.sourceTextfield.scroll = this.scrollbar.scrollPosition + 1;
this.scrollPosition = this.scrollbar.scrollPosition;
this.refresh();
}

o.setSize=function(width,height){
this.sourceTextfield._width = width;
this.sourceTextfield._height = height;

this.width=width;
this.height=height-this.lineHeight;
this.maxWidth=this.MAX_LINE_TOLERANCE*this.width;
this.updateScrollbar();
this.refresh();
}

o.getSize=function(width,height){
return {width:this.width,height:this.height+this.lineHeig ht};
}


o.updateScrollbar =function(){
this.sourceTextfield.text=this.sourceTextfield.tex t;
this.sourceTextfield.scroll = this.scrollbar.scrollPosition + 1;
this.scrollbar._x = this._x + this.width + 11;
this.scrollbar._y = this._y + 7;
this.scrollbar.setScrollProperties( 1 + this.sourceTextfield.bottomScroll - this.sourceTextfield.scroll, 0 , this.sourceTextfield.maxscroll+1);
this.scrollPosition = this.scrollbar.scrollPosition = this.sourceTextfield.scroll -1;
this.scrollbar._visible =(this.sourceTextfield.maxscroll > 1);
this.scrollbar.setSize( 16, this.height);

//this.scrollbar._visible = true;

}

o.refresh=function(){
var nextDepth=0;
var nextY=0;
var nextX=0
var finished=false;
var currentParagraph=0;
var currentWord=0;
var currentLine=[];
var ignoreLines = this.scrollPosition;
while (!finished){
if (this.words[currentParagraph].length>currentWord){
this.createTextField("t"+nextDepth,nextDepth,nextX ,nextY,0,0);
var txt=this["t"+nextDepth++];
txt.autoSize="left";
txt.selectable=false;
txt.setNewTextFormat(this.textFormat)
txt.embedFonts=this.sourceTextfield.embedFonts;
txt.text=this.words[currentParagraph][currentWord++];
if (nextX+txt._width>this.width){
var squeeze=false;
if (this.ALLOW_SQUEEZE && currentLine.length<this.MAX_SQUEEZE_WORDS && nextX+txt._width<this.maxWidth){
currentLine.push(txt);
squeeze=true;
}
if (squeeze || currentLine.length==1){
var letters=[];
for (var i=0;i<currentLine.length;i++){
letters=letters.concat(currentLine[i].text.split(""));
letters.push(" ");
currentLine[i].text="";
}
letters.pop();

currentLine=[];
nextX=0;

for (var i=0;i<letters.length;i++){
this.createTextField("t"+nextDepth,nextDepth,nextX ,nextY,0,0);
var ltr=this["t"+nextDepth++];
ltr.autoSize="left";
ltr.selectable=false;
ltr.setNewTextFormat(this.textFormat)
ltr.embedFonts=this.sourceTextfield.embedFonts;
ltr.text=letters[i];
currentLine.push(ltr);
}

}

var spaceSize=this.width;
for (var i in currentLine){
spaceSize-=currentLine[i]._width;
}
spaceSize/=currentLine.length-1;
nextX=currentLine[0]._width+spaceSize;
for (var i=1;i<currentLine.length-1;i++){
currentLine[i]._x=nextX;
nextX+=currentLine[i]._width+spaceSize;
}
currentLine[i]._x=this.width-currentLine[i]._width;
if (!squeeze){
currentLine=[txt];
nextX=txt._width+this.minSpace;
} else {
currentLine=[];
nextX=0;
}
if (ignoreLines>0){
ignoreLines--;
for (var i=0; i<nextDepth-1;i++){
this["t"+i]._visible = false;
this["t"+i].removeMovieClip();


}
} else {
nextY+=this.lineHeight;
}
if (nextY>=this.height) {
txt.text="";
finished=true;
}
txt._x=0;
txt._y=nextY;

} else {
currentLine.push(txt);
nextX+=txt._width+this.minSpace
}
} else {
currentParagraph++;
currentWord=0;
nextX=0;
if (ignoreLines>0){
ignoreLines--;
} else {
nextY+=this.lineHeight;
}
currentLine=[];
if (nextY>=this.height || this.words.length<=currentParagraph) finished=true;
}
}
if (this.lastDepth>nextDepth){
for (var i=nextDepth;i<this.lastDepth;i++){
this["t"+i]._visible=false;
this["t"+i].removeMovieClip();
}
}
this.lastDepth=nextDepth;
}

delete o;

#endinitclip
MCB is offline   Reply With Quote
Reply


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
gotoAndPlay("frame") when already on "frame". Why no code execution? jasonyen ActionScript 1.0 (and below) 0 12-13-2004 06:25 AM
difference the way a mc and a button run code? mobzilla Simple Stuff (Newbies) 2 09-13-2004 02:00 PM
code consolidation subquark ActionScript 1.0 (and below) 11 01-21-2003 11:53 PM
Adding code to a component event handler? BlueTree ActionScript 1.0 (and below) 0 12-02-2002 11:17 PM
code not working jaredly ActionScript 1.0 (and below) 6 06-05-2002 07:56 PM


All times are GMT. The time now is 12:42 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.