PDA

View Full Version : Children affecting each other



Lango
August 29th, 2007, 08:29 PM
Hey

This is my first post :) I'm getting into AS3 and i'm having trouble with my children affecting each other. This is the code



package {
//
//
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Shape;
//
//
public class Waves extends MovieClip {
//
//
private var main_wave:Wave;
private var temp_wave:Wave;
//
//
public function Waves() {
trace("Waves");
loadMainWave();
}
//
//
private function loadMainWave():void {
trace("loadMainWave");

this.main_wave = new Wave();
this.main_wave.blendMode = "overlay";
this.main_wave.alpha = 1;
this.main_wave.scaleY = 0.7;
this.main_wave.x = 0;
this.addChild(this.main_wave);

this.temp_wave = new Wave();
this.temp_wave.blendMode = "overlay";
this.temp_wave.alpha = 1;
this.temp_wave.scaleY = 1.5;
this.temp_wave.x = 0;
this.addChild(this.temp_wave);

var ref:Shape = new Shape();
ref.graphics.beginFill(0xff0000);
ref.graphics.lineStyle(0, 0x000000);
ref.graphics.drawCircle(2, 2, 2);
ref.graphics.endFill();
ref.x = 0;
this.addChild(ref);

}
}
}
Wave is a animated (tweened) movie clip. Now if i change
this.temp_wave.x = 0 to another value, say 100, then ref, temp_wave and main_wave, all move across. Temp_wave and main_wave no longer line up though.

Now, i'm pretty sure this shouldn't be happening slash i don't want this to happen. First i thought that i might actually be moving the graphic inside the movie clip (i hope not) but that doesn't explain why ref would move as well.

Can anyone see what i'm doing wrong? I tried searching for answers, but i'm not even sure what i'm really looking for.

Cheers

Lango

****EDIT****
The same thing happens if i change main_wave.x, but NOT if i change ref.x

Lango
September 3rd, 2007, 02:31 AM
What no loving?

Anyway, i've solved my problem, if anyone was interested. What was happening was the instance that creates the waves instance, would set its x position to half its width.

This affected it because the when i moved objects around inside waves, it would change its width, therefore changing its own x position. The children were not affecting each other at all :)