Copy link to clipboard
Copied
Hi All,
I am having an issue with AS3, which I cannot work out. Apologies if this is something very simple.
Basically, I have a pool of animations in the library. "testMc1", "testMc2", "testMc3", "testMc4", "testMc5". As these animations are composed of the same 'sub' symbols, this (to me) makes more sense than having external SWF's.
Anyway what I want to do is load one of these movies into the Scene (this works), then on each respective timeline call a panning x+y position function, which will almost act as a camera, this makes more sense than physically animating each x,y movement.
The Main Doc Class looks like this:
package {
import flash.display.*;
import flash.events.*;
import flash.ui.*;
import flash.display.MovieClip;
import flash.utils.getDefinitionByName;
public class Test extends MovieClip {
public function moveCanvas(xPos, yPos){
//trace("hello world"+MovieClip(root).containerMc.x);
containerMc.x=xPos;//doesnt work 1120 Access of unidentified property containerMc
containerMc.y=yPos;//doesnt work 1120 Access of unidentified property containerMc
}
public function addCanvas(){
if(movieName==null){
var movieName:String="testMc"+2;
var C:Class=Class(getDefinitionByName(movieName));
var animC:MovieClip=new C();
var container:MovieClip = new MovieClip();
addChild(container);
container.name="containerMc";
container.addChild(animC);
}
}
public function startMenu(){
addCanvas();
}
}
}
now inside and on the respective timelines we have "textMc1", "testMc2" we have this action at crucial parts of the animations:
trace("mcComplete"+this.parent.name);
Object(root).moveCanvas(40,40);
stop();
The Error I get once the function call hits is:
1120 access of unidentified property containerMc1120 Access of unidentified property containerMc.
Any help would be greatly appreciated, or suggestions on how to make this better!
Thanks in advance.
containerMc is not defined in that function. (actually, it's not defined anywhere.)
you have a name property of containerMc but that's not an object name. if your moveCanvas function needs to reference container, you could use getChildByName('containerMc');
Copy link to clipboard
Copied
in the publish setting tick 'permit debugging' so you can pinpoint the line of code triggering the error message.
Copy link to clipboard
Copied
Hi kglad the error is:
Test.as,Line 10,Column 4 1120:Access of undefined property containerMc
Test.as,Line 11,Column 4 1120:Access of undefined property containerMc
If I comment out these lines the movie works without errors. The ContainerMc.x isn't there so the reposition doesn't work - which means it is a pathing issue.
Copy link to clipboard
Copied
containerMc is not defined in that function. (actually, it's not defined anywhere.)
you have a name property of containerMc but that's not an object name. if your moveCanvas function needs to reference container, you could use getChildByName('containerMc');
Copy link to clipboard
Copied
Great, THANKS kglad.
Just changed to:
getChildByName('containerMc').x=xPos;
getChildByName('containerMc').y=yPos;
And works like a dream!
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Sorry, Just a quick follow up question:
The positional stuff all works now, however I can't seem to target the MovieClip to play using the same method. The playAnim() function doesn't work, am I missing something obvious? Have tried :
MovieClip('containerMc').play( ), MovieClip(root).containerMc.play and containerMc.play() - neither work
I can trace the xPosition in the same function so it is targeting the MovieClip.
public function startAnim(){
btnStart.removeEventListener(MouseEvent.CLICK, gotoMenu);
btnStart.addEventListener(MouseEvent.CLICK, gotoMenu);
stop();
//stage.addChild(anim1);
if (movieName==null){
var movieName:String="anim1";
}
var C:Class=Class(getDefinitionByName(movieName));
function changeAnim(n){
charMc.visible=false;
var movieName:String="anim"+1;
var C:Class=Class(getDefinitionByName(movieName));
var animC:MovieClip=new C();
addChildAt(animC,1);
animC.name="containerMc";
getChildByName('containerMc').x=508;
getChildByName('containerMc').y=420;
getChildByName('containerMc').scaleX=0.25;
getChildByName('containerMc').scaleY=0.25;
}
changeAnim(1);
}
function playAnim(){
trace("play anim"+getChildByName('containerMc').x);//does work
getChildByName('containerMc').play();//doesnt work
}
Copy link to clipboard
Copied
i don't see where you're calling playAnim() in that class and if you're calling it from outside the class try making it public.
but if that trace works, there's some other problem like a stop() somewhere that's preventing you from seeing what you expect. using a goto can also be helpful for debugging.
Copy link to clipboard
Copied
Hi kglad, the function call is on an embedded button in another MovieClip. ------------------- public function playAnim(){ trace("play anim"+getChildByName('containerMc').x); getChildByName('containerMc').play(); } ------------------- The error I get (after making the function public) is: Call to a possibly undefined play through a reference with static type flash.DisplayObject Any ideas?
Copy link to clipboard
Copied
use:
MovieClip(getChildByName('containerMc').play();
Copy link to clipboard
Copied
Great! Thanks kglad!!!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now