Skip to main content
stuartf76130223
Inspiring
February 20, 2017
Answered

AS3 Root Function issue

  • February 20, 2017
  • 2 replies
  • 1254 views

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.

This topic has been closed for replies.
Correct answer kglad

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');

2 replies

stuartf76130223
Inspiring
February 21, 2017

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

  }

kglad
Community Expert
Community Expert
February 21, 2017

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.

stuartf76130223
Inspiring
February 21, 2017

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?

kglad
Community Expert
Community Expert
February 20, 2017

in the publish setting tick 'permit debugging' so you can pinpoint the line of code triggering the error message.

stuartf76130223
Inspiring
February 20, 2017

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.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 20, 2017

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');