Reputation: 21
recently I got many (about 70) #1119 and #1120 errors in Flash. I've searched the web, but none of the solutions has solved my problem. Attempting to find the cause of the error myself, I made a new Flash animation. The contents:
A movieClip called "nr1" without instance name. Inside of nr1 there are two movieClips, "nr2" with the instance name "ob2" and "nr3" with the instance name "ob3". Associated with nr2 is the as3 class file "nr2.as3". Here is the code inside nr2.as3:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class nr2 extends MovieClip {
public function nr2() {
// constructor code
this.addEventListener(MouseEvent.CLICK,func1);
}
function func1(e:MouseEvent){
parent.ob3.x += 50;
}
}
}
This should refer to the object with the instance name "ob3", which has the same parent as this (nr2). Still, I get two identical #1119 errors at line 15 (parent.ob3.x += 50;). How do I refer to an object with the same parent via an as3 class file?
Upvotes: 0
Views: 76
Reputation: 2188
Agree with Pan, it's not a good idea to control a child from another child. Let the parent (nr1) who has references to both child do the control. So you should create nr1 class
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class nr1 extends MovieClip {
public function nr1() {
// constructor code
ob2.addEventListener(MouseEvent.CLICK,func1);
}
function func1(e:MouseEvent){
ob3.x += 50;
}
}
}
Upvotes: 0
Reputation: 2101
It isn't a good idea to set ob3's property in nr2. You could dispatch an event in nr2, and add eventListener in parent, so the parent could catch the event and do something with bo3.
If you really want to set ob3's property in nr2, try this
function func1(e:MouseEvent) {
var ob3:MovieClip = parent['ob3'] as MovieClip;
if (ob3)
{
ob3.x += 50;
}
}
Upvotes: 1