Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 Root Function issue

Explorer ,
Feb 20, 2017 Feb 20, 2017

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.

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 20, 2017 Feb 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');

Translate
Community Expert ,
Feb 20, 2017 Feb 20, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2017 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2017 Feb 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');

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2017 Feb 20, 2017

Great, THANKS kglad.

Just changed to:

getChildByName('containerMc').x=xPos;

getChildByName('containerMc').y=yPos;

And works like a dream!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2017 Feb 20, 2017

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2017 Feb 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

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2017 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2017 Feb 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2017 Feb 21, 2017

use:

MovieClip(getChildByName('containerMc').play();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2017 Feb 21, 2017

Great! Thanks kglad!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2017 Feb 21, 2017
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines