Skip to main content
Participating Frequently
May 30, 2018
Answered

Difficulty adding children with AS3 Advanced Layers

  • May 30, 2018
  • 1 reply
  • 268 views

I use AS3 on Adobe Animate with the built-in Camera function. My scene has a man walking in front of a field of flowers. Pressing up/down makes him walk into the flowers behind him, with the flowers appearing above his feet. Pressing left/right makes him move left and right, while the camera follows his movements and the flowers parallax behind him.

Movement code:

 if (downKey == true) { 
man
.scaleX = 1;
man
.scaleY = 1;
this.addChild (man)
}
if (upKey == true) {
man
.scaleX = .8;
man
.scaleY = .8;
this.addChild (flowers)
}

Camera code:

import fl.VirtualCamera; 
var cameraObj = VirtualCamera.getCamera(root); 
cameraObj
.setPosition(0,0,0); 

stage
.addEventListener(Event.ENTER_FRAME, paralaxing) 
function paralaxing( e:Event 😞void {
if (rightKey == true) {
cameraObj
.moveBy(-13,0,0);
} 
if (isLeft == true) {
cameraObj
.moveBy(13,0,0);
}
}

My issue: I cannot re-arrange the child objects while using the Advanced Layers parallax function at the same time. I currently use the "addChild" method to ensure the right objects appear at the front, but instead of parallaxing the flowers become "glued" to the camera and move with the man.

It seems that the (this.addChild (flowers)) function is adding the flowers on the camera itself, rather than the stage they belong in (???). Any idea how to fix this?

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

Please notice that when using Advanced Layers, the layers become Movie Clips themselves.

Create timeline layers with Animate CC

Check if this is not the issue first.

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
May 30, 2018

Hi.

Please notice that when using Advanced Layers, the layers become Movie Clips themselves.

Create timeline layers with Animate CC

Check if this is not the issue first.

Regards,

JC