PDA

View Full Version : Returning scaleX on movieclip



vivaretro
April 25th, 2008, 10:04 AM
I have a fla file with movieClips representing state counties. I have it so if you click
on a county it will trace that countie's name. Problem is I also want to trace it's current
scale but I get the following error instead:

County selected is Umatilla
ReferenceError: Error #1069: Property scaleX not found on String and there is no default value.
at County/selectedCounty()

Here is the code:


// main county

package
{
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.Font;
import flash.display.Sprite;
import flash.utils.*;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;




public class County extends MovieClip // what extends means is that in addition to all the below properties and methods you're also
// adding the methods of movieclips
// County adds the properties of movieclips plus a mouseclick listener and a return of the name of the selected county?
{

// this event listener had to be within its own function to work
// this is a constructor
// this is a method too
// this is a constructor because its named after the class
public function County()
{
addEventListener(MouseEvent.CLICK , selectedCounty); // if the mouuse is clicked it calls the next function below which returns the name of the
// selected movieclip county.



}

// this is also a method
private function selectedCounty(event:MouseEvent):void
{
trace("County selected is " + this.Name()); // this calls upon the next function which gets the qualified class name of the movieclip
var currentCounty = this.Name();
trace (currentCounty.scaleX);


}

// another method of course
// this function returns name of the county
public function Name()
{

return getQualifiedClassName(this); // puts the countie's name in the Name variable?

}



}
}

// you can put functions and call such functions here as well

skineh
April 25th, 2008, 10:27 AM
The problem is right there in your error message - You're assigning a String to currentCountry, not the display object whose scaleX you want to retrieve. It'd be like trying to do...

"Hi, I'm a string!".scaleX

Since I haven't seen the rest of your code, I can't tell you for sure what you need to get your scaleX from, but just from looking at this snippet it'd be fair to guess that you'll want to use this.scaleX

vivaretro
April 25th, 2008, 10:32 AM
So can I apply this.scaleX to a variable?


The problem is right there in your error message - You're assigning a String to currentCountry, not the display object whose scaleX you want to retrieve. It'd be like trying to do...

"Hi, I'm a string!".scaleX

Since I haven't seen the rest of your code, I can't tell you for sure what you need to get your scaleX from, but just from looking at this snippet it'd be fair to guess that you'll want to use this.scaleX

icio
April 25th, 2008, 10:35 AM
If, however, the movieclip that you are trying to reference has the instance name equal to the string value that you are selecting and you are wanting to return the scaleX of said movieclip, you in-fact want to do the following:


var currentCounty:MovieClip = ParentMovieClip.getChildByName(this.Name());
trace (currentCounty is DisplayObject, currentCounty.scaleX);

And I'm not entirely convinced that the function you're wanting to use is `getQualifiedClassName` when you use it, but then I don't know what your application is about.

Hope that helps :thumb:

vivaretro
April 25th, 2008, 10:39 AM
Thanks everyone for the help! Much appreciated. I'll give it a try.


If, however, the movieclip that you are trying to reference has the instance name equal to the string value that you are selecting and you are wanting to return the scaleX of said movieclip, you in-fact want to do the following:

ActionScript Code:

var currentCounty:MovieClip = <i>ParentMovieClip</i>.getChildByName(this.Name());
trace (currentCounty is DisplayObject, currentCounty.scaleX);





And I'm not entirely convinced that the function you're wanting to use is `getQualifiedClassName` when you use it, but then I don't know what your application is about.

Hope that helps :thumb:

Felixz
April 25th, 2008, 10:52 AM
private function selectedCounty(event:MouseEvent):void {
trace("County selected is " + getQualifiedClassName(event.target);
trace (event.target.scaleX);
}