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

Can't change child.x

New Here ,
Aug 08, 2015 Aug 08, 2015

Creating a child creates it at the x and y of the parent platform. When I try to change the onion.x it does not return an error but it also does not change the x.

The child class.

package {

  import flash.display.MovieClip;

  import flash.events.Event;

  import com.Platform

  public class Onion extends MovieClip {

  var onionSpeed;

  public function Onion(onionSpeed, pWidth) {

  this.addEventListener(Event.ENTER_FRAME, loop);

  this.x += pWidth;

  }

  function loop(e: Event): void {

  this.x -= onionSpeed;

}

}

}

The parent class.

package {

  import flash.events.Event

  import flash.display.MovieClip;

  public class Platform extends MovieClip {

  var platformSpeed;

  var platformWidth;

  public function Platform() {

  this.addEventListener(Event.ENTER_FRAME, loop)

  this.x = 1280;

  this.y = Math.floor(Math.random() * 550 + 200);

  this.platformSpeed = Math.random() * 8 + 6;

  this.platformCollision.width = (Math.random() * 400 + 200)

  platformWidth = this.platformCollision.width;

  if (Math.random() > 0.5) {

  var onion = new Onion(this.platformSpeed, this.platformWidth);

  this.platformContainer.addChild(onion);

  }

  }

  public function loop(e: Event): void {

  this.x -= platformSpeed;

  }

  public function removeSelf(): void {

  this.removeEventListener(Event.ENTER_FRAME, loop);

  this.parent.removeChild(this);

  }

  }

}

I tried

import com.Platform

in the onion class and using the platform.width but I got the error "1172: Definition com:Platform could not be found."

TOPICS
ActionScript
264
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 , Aug 08, 2015 Aug 08, 2015

use:

package {

  import flash.display.MovieClip;

  import flash.events.Event;

  public class Onion extends MovieClip {

  var onionSpeed;

  public function Onion(_onionSpeed, pWidth) {

onionSpeed=_onionSpeed;

  this.addEventListener(Event.ENTER_FRAME, loop);

  this.x += pWidth;

  }

  function loop(e: Event): void {

  this.x -= onionSpeed;

}

}

}

p.s. you should type your variables.

Translate
Community Expert ,
Aug 08, 2015 Aug 08, 2015

use:

package {

  import flash.display.MovieClip;

  import flash.events.Event;

  public class Onion extends MovieClip {

  var onionSpeed;

  public function Onion(_onionSpeed, pWidth) {

onionSpeed=_onionSpeed;

  this.addEventListener(Event.ENTER_FRAME, loop);

  this.x += pWidth;

  }

  function loop(e: Event): void {

  this.x -= onionSpeed;

}

}

}

p.s. you should type your variables.

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
New Here ,
Aug 08, 2015 Aug 08, 2015

I'm unsure how this fixed the problem, but thank you very much.

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 ,
Aug 08, 2015 Aug 08, 2015
LATEST

your onionSpeed was undefined outside of the constructor.  i fixed that.

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