Copy link to clipboard
Copied
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."
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I'm unsure how this fixed the problem, but thank you very much.
Copy link to clipboard
Copied
your onionSpeed was undefined outside of the constructor. i fixed that.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now