Skip to main content
Inspiring
August 20, 2007
Question

Changing Properties via AS3

  • August 20, 2007
  • 11 replies
  • 1724 views
I'm trying to write the proper AS3 script to change the properties of a single movie clip called blueMC. I'm using input text fields that have instance names with a button next to them to trigger the change in the MC's properties. Here's my code thus far:

yscale_btn.addEventListener(MouseEvent.CLICK, yScale);
xscale_btn.addEventListener(MouseEvent.CLICK, xScale);
alpha_btn.addEventListener(MouseEvent.CLICK, alphaChange);
rotate_btn.addEventListener(MouseEvent.CLICK, rotateChange);
xloc_btn.addEventListener(MouseEvent.CLICK, xLoc);
yloc_btn.addEventListener(MouseEvent.CLICK, yLoc);

function yScale(event:MouseEvent):void {
blueMC.scaleY = yScale.text;
}
function xScale(event:MouseEvent):void {
blueMC.scaleX = xScale.text;
}
function alphaChange(event:MouseEvent):void {
blueMC.alpha = alphaChange.text;
}
function rotateChange(event:MouseEvent):void {
blueMC.rotate = rotateChange.text;
}
function xLoc(event:MouseEvent):void {
blueMC.x = xLoc.text;
}
function yLoc(event:MouseEvent):void {
blueMC.y = yLoc.text;
}

When I test the movie, I get the following errors: 1023: Incompatible override and 1021: Duplicate Function Definition.

I don't see anything duplicated in my functions, they all seem pretty unique other than the format. Can you help?
This topic has been closed for replies.

11 replies

kglad
Community Expert
Community Expert
August 26, 2007
you're too confused to help.
padrepioAuthor
Inspiring
August 25, 2007
It was an old Flash MX file that I then saved as a Flash CS3 file. Will that not work? I'll try taking all of the content out of the file and put it into a new AS3 file.

thanks.

kglad
Community Expert
Community Expert
August 26, 2007
the file you posted has as1 code in it. where's the code you posted in this forum?
padrepioAuthor
Inspiring
August 26, 2007
Here's the code:

yscale_btn.addEventListener(MouseEvent.CLICK, yScale);
xscale_btn.addEventListener(MouseEvent.CLICK, xScale);
alpha_btn.addEventListener(MouseEvent.CLICK, alphaChange);
rotate_btn.addEventListener(MouseEvent.CLICK, rotateChange);
xloc_btn.addEventListener(MouseEvent.CLICK, xLoc);
yloc_btn.addEventListener(MouseEvent.CLICK, yLoc);

function yScale(event:MouseEvent):void {
blueMC.scaleY = yScale.text;
}
function xScale(event:MouseEvent):void {
blueMC.scaleX = xScale.text;
}
function alphaChange(event:MouseEvent):void {
blueMC.alpha = alphaChange.text;
}
function rotateChange(event:MouseEvent):void {
blueMC.rotate = rotateChange.text;
}
function xLoc(event:MouseEvent):void {
blueMC.x = xLoc.text;
}
function yLoc(event:MouseEvent):void {
blueMC.y = yLoc.text;
}
kglad
Community Expert
Community Expert
August 25, 2007
that's not an as3 file.
padrepioAuthor
Inspiring
August 25, 2007
www.lemieux-design.net/changeMCvar.zip
kglad
Community Expert
Community Expert
August 25, 2007
post a link to your fla
padrepioAuthor
Inspiring
August 25, 2007
If you look at my code at the beginning of this post, you'll see that all of the functions have unique names:

function yScale(event:MouseEvent):void {
blueMC.scaleY = yScale.text;
}
function xScale(event:MouseEvent):void {
blueMC.scaleX = xScale.text;
}
function alphaChange(event:MouseEvent):void {
blueMC.alpha = alphaChange.text;
}
function rotateChange(event:MouseEvent):void {
blueMC.rotate = rotateChange.text;
}
function xLoc(event:MouseEvent):void {
blueMC.x = xLoc.text;
}
function yLoc(event:MouseEvent):void {
blueMC.y = yLoc.text;
}

Per the instructions, I've encased the action in the function with the Number() function as follows:

blueMC.scaleY = Number(yScale.text);

kglad
Community Expert
Community Expert
August 24, 2007
pay attention:

the duplicate function definition messages means you have two functions with the same name. remove one.

the incompatible override is probably because you're not using the Number() function as discussed previously.
kglad
Community Expert
Community Expert
August 21, 2007
yes.
padrepioAuthor
Inspiring
August 24, 2007
I'm still getting two errors:

1023: Incompatible override
1021: Duplicate function definition

In this line of code:

function yScale(event:MouseEvent):void {
blueMC.scaleY = yScale.text;
}

Am I supposed to declare which mouse event triggers like this:

function yScale(event:MouseEvent):void {
blueMC.scaleY(event:CLICK) = yScale.text;
}

With this I get this error:

1084: Syntax error

Inspiring
August 20, 2007
The problem is that text in your text fields are strings and the properties you are trying to set are numbers. Previous versions of ActinScript won't complaint about this. But this version is very strict. So you have to convert the strings to number using the Number, parseInt or parseFloat funtions.

Number is more generic, while parseInt is for integer numbers and float is used for any integer of floating point number.
padrepioAuthor
Inspiring
August 21, 2007
That makes sense but would the execution be something like this?

blueMC.rotate = Number(rotateChange.text);
kglad
Community Expert
Community Expert
August 20, 2007
use the Number() function.
padrepioAuthor
Inspiring
August 20, 2007
??? Sorry. The Number function?