Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping clip (textfield) should get new content each lap

Status
Not open for further replies.

sirugo

Programmer
Aug 1, 2000
162
SE
I have a text field as a movieclip.
The field is moving across the screen. Then it starts over.
I want to change the content of the text field for each lap it completes.

I'm a newbie but I know some ActionScript, I know how to create clips and how to assign values to text fields.

Still I don't know how to make combination of frames/commands to succeed with this.

Let's say - for a start - that the field should contain "1" for the first turn across the screen, then "2" for the second turn, then "3", up to "10". Then start all over from "1" again.

Anyone?
 
The following does what you described (if I didn't misunderstand you!)

[tt]//
this.createEmptyMovieClip("mcX", 0);
mcX.createTextField("tfX", 0, 0, 0, 20, 20);
mcX.n = 1;
mcX.tfX.text = ""+mcX.n;
var iniX:Number = -mcX._width;
mcX._x = iniX;
var speed:Number = 5;
mcX.onEnterFrame = function() {
if (this._x>=Stage.width) {
this.n>=10 ? this.n=1 : this.n++;
this.tfX.text = ""+this.n;
this._x = iniX;
} else {
this._x += speed;
}
};
stop();
//[/tt]

Kenneth Kawamoto
 
Thanks! I get the point.

But I'm also getting some errors that I cannot sort out.
I changed Stage.width to a constant (400) but it didn't help.
Looks good to me though. Help?

this.createEmptyMovieClip("mcX", 0);
mcX.createTextField("tfX", 0, 0, 0, 20, 20);
mcX.n = 1;
mcX.tfX.text = ""+mcX.n;
var iniX:Number = -mcX._width;
mcX._x = iniX;
var speed:Number = 5;
mcX.onEnterFrame = function() {
    if (this._x>=Stage.width) {
        this.n>=10 ? this.n=1 : this.n++;
        this.tfX.text = ""+this.n;
        this._x = iniX;
    } else {
        this._x += speed;
    }
};
stop();
 
Oops. Forgot the error code:

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 9: Operator '=' must be followed by an operand
    if (this._x>=Stage.width) {

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 10: Syntax error.
        this.n>=10 ? this.n=1 : this.n++;

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 11: Syntax error.
        this.tfX.text = ""+this.n;

Total ActionScript Errors: 3 Reported Errors: 3

 
Seems like a "basic" error.
What about that operand issue?
 
Hi again

I looke elsewhere and I got the tip not to copy the code you wrote.
So I wrote every single character myself and the errors were gone. Also the clip works exactly as I wanted!

THANKS!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top