Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Movieclip: Gettextdata And Addscroll, Automate common text field operations.
gsb
post May 28 2004, 02:55 PM
Post #1


Regular Dot
Group Icon
Group: *Premier*
Posts: 52
Joined: 22-May 04
From: Seattle
Member No.: 31





PURPOSE:
These two prototypes, getTextData and addScroll, are applied to a movieclip to load external text into the movieclip's associated text field and when loaded, to add a vertical scroll bar if needed.

SPECIAL NOTE: The addScroll requires a SWiSHmax build of 2004.04.30 or later.

PROTOTYPE:
CODE
// Load data from url into text field
movieclip.prototype.getTextData = function(url) {
    this.tfLoader=new LoadVars();
    this.tfLoader.self=this;
    this.tfLoader.onData=function(s) {
        delete this.self.onEnterFrame;
        if(typeOf(s)=="string") {
            if(!this.self._text.html) {
                s=s.split("\r").join("");
                this.self._text.text=s;
            } else this.self._text.htmltext=s;
            this.self.addScroll();
        }
        delete this.self.tfLoader;
    };
    this.tfLoader.load(url);
    this.onEnterFrame=function() {
        this._text.text=((x=this.tfLoader.getBytesTotal())>0Math.ceil(100*this.tfLoader.getBytesLoaded()/x):0) add "% loaded";
    };
};

// Add vertical scroll bar to text field and show if needed
movieclip.prototype.addScroll=function(sbw,sbfc,sbbc) {
    if(typeOf(this._text.onScroller)!="function") {
        var obj=this._text;
        if(typeOf(obj)!="object") return;
        if(sbw==undefined) var sbw=14;
        if(sbfc==undefined) var sbfc=0xCCCCCC;
        if(sbbc==undefined) var sbbc=0x000000;
        obj.ow=obj._width;
        obj._width-=sbw;
        obj.lms=0;
        var mc=obj._parent.createEmptyMovieClip(obj._name+"_sb_",999);
        mc._x=obj._x+obj._width;
        mc._y=obj._y;
        mc.ttf=obj;
        var ss=mc.createEmptyMovieClip("_ss_",1);
        ss.beginFill(0xFFFFFF,100);
        ss.lineStyle(1,sbbc,100);
        ss.lineTo(0,obj._height );
        ss.lineTo(sbw,obj._height);
        ss.lineTo(sbw,0);
        ss.lineTo(0,0);
        ss.endFill();
        db=function(o) {
            o.lineStyle(1,sbbc,100);
            o.beginFill(sbfc,100);
            o.lineTo(0,sbw);
            o.lineTo(sbw,sbw);
            o.lineTo(sbw,0);
            o.lineTo(0,0);
            o.endFill();
            o.beginFill(0,100);
            o.moveTo(sbw/2,sbw/4);
            o.lineTo(sbw/4,3*sbw/4);
            o.lineTo(3*sbw/4,3*sbw/4);
            o.lineTo(sbw/2,sbw/4);
            o.endFill();
        };
        var up=mc.createEmptyMovieClip("_up_",2);
        db(up);
        var dn=mc.createEmptyMovieClip("_dn_",3);
        db(dn);
        dn._rotation=180;
        dn._y=obj._height;
        dn._x=sbw;
        var br=mc.createEmptyMovieClip("_br_",4);
        br.onPress=function() {
            this._parent.ttf.onScroller=null;
            this.startDragUnlocked(this._x,this._x,sbw,de);
            this.onEnterFrame=function() {
                this.spos=Math.floor(this._parent.ttf.maxscroll*(this._y-sbw+1)/(de-sbw+1));
                if(this.spos>this._parent.ttf.maxscroll/2) this.spos++;
                if(this.spos!=this._parent.ttf.scroll) this._parent.ttf.scroll=this.spos;
            };
        };
        br.onRelease=br.onReleaseOutside=function() {
            this.stopDrag();
            delete this.onEnterFrame;
            this._parent.ttf.onScroller=this._parent.ttf.saved;
            this._parent.ttf.onScroller();
        };
        dn.onPress=function() {
            mc.onEnterFrame=function() {
                if(this.ttf.scroll+1>this.ttf.maxscroll) delete this.onEnterFrame;
                else this.ttf.scroll+=1;
            };
        };
        dn.onRelease=dn.onReleaseOutside=function() { delete mc.onEnterFrame; };
        up.onPress=function() {
            mc.onEnterFrame=function() {
                if(this.ttf.scroll<2) delete this.onEnterFrame;
                else this.ttf.scroll-=1;
            };
        };
        up.onRelease=up.onReleaseOutside=function() { delete mc.onEnterFrame; };
        ss.onPress=function() {
            if(this._ymouse<br._y)
                this._parent.ttf.scroll=Math.max(1,2*this._parent.ttf.scroll-this._parent.ttf.bottomScroll-1);
            else
                this._parent.ttf.scroll=Math.min(this._parent.ttf.maxscroll,this._parent.ttf.bottomScroll+1);
        };
        obj.saved=obj.onScroller=function() {
            br._y=sbw+(this._height-sp-2*sbw)*(this.scroll-1)/(this.maxscroll-1);
            if(this.maxscroll==1) {
                mc._visible=false;
                this._width=this.ow;
            } else {
                if(mc._visible==false) {
                    mc._visible=true;
                    this._width-=sbw;
                }
                if(this.maxscroll!=this.lms) {
                    this.lms=this.maxscroll;
                    x=this.bottomScroll-this.scroll+1;
                    sp=MAth.round((this._height-2*sbw)*(x)/(x+this.maxscroll));
                    de=obj._height-sp-sbw;
                    br.clear();
                    br.lineStyle(1,sbbc,100);
                    br.beginFill(sbfc,100);
                    br.lineTo(sbw,0);
                    br.lineTo(sbw,sp);
                    br.lineTo(0,sp);
                    br.lineTo(0,0);
                    br.endFill();
                }
            }
        };
    } else this._text.onScroller();
};


USAGE: textfield.getTextData( "textfield.txt" );

EXAMPLE:
CODE
// SWiSH text field initialization
  textfield1.getTextData( "textfield1.txt" );

  // ActionScript text field initialization
  o=createEmptyMovieClip("textfield2",1);
  o.createTextField("_text",0,200,40,120,80);
  (o=o._text).border=1;
  o.multiline = true;
  o.wordWrap = true;
  o.html = true;
  textfield2.getTextData( "textfield2.txt" );
 
+Quote Post  Go to the top of the page
*D*
post May 29 2004, 08:46 AM
Post #2


Merry KissMoose
Group Icon
Group: Main Team
Posts: 15,990
Joined: 18-May 04
From: North Pole
Member No.: 2





gsb any chance you could add a preview of this, sorry I'm extremely lost in what this actually is lol

blonde moment smile.gif
 
+Quote Post  Go to the top of the page
gsb
post May 29 2004, 12:14 PM
Post #3


Regular Dot
Group Icon
Group: *Premier*
Posts: 52
Joined: 22-May 04
From: Seattle
Member No.: 31





Well, I guess so, although my intent was a "code junkies corner." LOL

Here is the above example as is: .: LINK :.

And this is another with a large text file to show the load progress: .: LINK :.

In other words, it loads the text data and draws the vertical scroll bar.

gsb
 
+Quote Post  Go to the top of the page
elfantoush
post May 29 2004, 02:52 PM
Post #4


Getting Used To The Dots
Group Icon
Group: Member
Posts: 25
Joined: 28-May 04
Member No.: 56





Great work gsb.
 
+Quote Post  Go to the top of the page
*D*
post May 29 2004, 06:04 PM
Post #5


Merry KissMoose
Group Icon
Group: Main Team
Posts: 15,990
Joined: 18-May 04
From: North Pole
Member No.: 2





Ok ty gsb I'm with you now smile.gif
 
+Quote Post  Go to the top of the page
tupaq
post Dec 31 2004, 12:52 AM
Post #6


New Member
Group Icon
Group: Member
Posts: 5
Joined: 31-December 04
Member No.: 1,605





Great work

Tip-Hat.gif
 
+Quote Post  Go to the top of the page
oliverp
post Mar 4 2005, 09:05 PM
Post #7


New Member
Group Icon
Group: Member
Posts: 9
Joined: 4-March 05
Member No.: 2,397





boooooowwwww...thnx for good job
 
+Quote Post  Go to the top of the page
Eddie_K
post Mar 5 2005, 02:27 AM
Post #8


Hush now, I'm thinking...
Group Icon
Group: *Premier*
Posts: 3,977
Joined: 25-May 04
From: Heaven
Member No.: 47





Great stuff Greg. Thanks for sharing with us.

Eddie
 
+Quote Post  Go to the top of the page
shawnastone
post Jun 4 2005, 06:52 AM
Post #9


New Member
Group Icon
Group: Member
Posts: 6
Joined: 4-June 05
Member No.: 4,468



I would love to see the examples when you are back on line.
 
+Quote Post  Go to the top of the page
kikezea
post Jul 5 2006, 07:23 AM
Post #10


New Member
Group Icon
Group: Member
Posts: 1
Joined: 20-May 06
Member No.: 11,325





This is a very powerfull script, but i´m sorry it doesn´t work with me, i´m shure it´s my fault, can you explain more the scritp, if you have to create the text in swish, in what places will be each script.


Thanks, Regards


Kike Zea

This post has been edited by kikezea: Jul 5 2006, 09:39 AM
 
+Quote Post  Go to the top of the page

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 29th July 2010 - 11:06 PM
Full and Final offers | Package Holidays | Home Insurance | Cheap Plane Tickets | 0% Commission Currency