AS3 help!
- Started
- Last post
- 12 Responses
- WhiteFace
Trying to do what I thought was a simple thing...
function playMovie(movieNumber) {
this.movie[movieNumber].x = 100;
}So i'm passing the movieNumber when I call the function...
playMovie(5);
But it's not working? I'm getting the crazy error, "TypeError: Error #1010: A term is undefined and has no properties. at Main_fla::MainTimeline/playMovie...
Any ideas, thanks.
- Ancillary0
Am I correct in saying you are trying to set the x position of an object in an array called "movie" to 100?
I don't think there are any problems there. Where are you setting the objects in the array? Sometimes this error occurs when you define objects in the array in the class declaration, ie before the constructor function, ie before the class has been added to the stage, therefore not allowing for a correct reference to the display objects.- Yes so in the example above movie5 would have been set to 100WhiteFace
- WhiteFace0
The "moviex" movieclips are just on the main stage (1 - 9) am I right to be using [ square brackets? ]
- CyBrain0
It would help if you would post all your code if possible or at least the part where you set up your array.
- jpea0
first, is movie5 your variable reference to that clip or is it the instance name? (or both?)
if you defined it by something like:
var movie5:MovieClip = new MovieClip()
then you can reference it without quotes. If you defined it as an instance name, you can reference it like this:
this['movie'+movieNumber]
or maybe use:
var mc = this.getDefinitionByName('movie...
mc.x = 100
- Ancillary0
yes, but a reference to them must be first passed into the array. so you have nine movie clips on stage each with instance names myMovie1, myMovie2.... myMovie9
and then at the top of your frame script:
var movie:Array = new Array[myMovie1,myMovie2.....,myM...
- kingsteven0
you have a movie clip called '5'?
or 'movie5'
if it's 'movie5' you can use this.movie['movie'+5].x
- WhiteFace0
there is no array, I have this for each of the buttons...
playMoviebutton1.addEventListene...
I know this is shit but was working fine before I tried the x thing.
- funkage0
I presume you're trying to access movieclips on the stage named 'movie1' to 'movie9'. What jpea and Ancillary said works, but you may also try:
function playMovie(movieNumber:int):void {
var movie:MovieClip = this.getChildByName("movie"+movi... as MovieClip;
movie.x = 100;
}
- WhiteFace0
So i have this for each of the 9 buttons...http://pastebin.ca/194...
- WhiteFace0
this['movie'+movieNumber] worked!!! thanks guys!!! (especially Jpea!)