2

I have created a movieclip1 :head, a second movieclip: body

created a movieclip that uses head and body and called that player.

And I create a simple moving animation : works great !

alt text

then I associated a class to head: Head.as

package  {

 import flash.display.MovieClip;


 public class Head extends MovieClip {


  public function Head() {
   trace("here");
   //this.alpha = 1;
  }
 }

}

I can see the trace output: Great !

When I uncomment trace this.alpha = 1 the ANIMATION IS STOPPED.

Why does this happen, and how can it be remedied?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
yarek
  • 11,278
  • 30
  • 120
  • 219

2 Answers2

2

You cannot change properties of a timeline animated object like that. The most common solution is to do the following.

Nest head and body inside of their own containers. So, for example, you might have

- head
  - head_content
- body
  - body_content

These would be your instance names. You would then tween head and body on the timeline like you are doing, but change the alpha of head by setting

head.head_content.alpha = .5;

Doing it this way will still allow you to tween your MovieClips / Sprites via the timeline and change their properties via ActionScript.

Here is an example:
http://d.pr/O5N8


To further explain why you can't do this... think of another property besides alpha, like positional properties like x, y. What would you expect your timeline tween to do if you put

this.x = 100;
this.y = -10; 

in your constuctor? Would you want the code based assignment to take precedence, or would you want the timeline placement to work? It might seem less obvious in your example, where you are just changing the alpha, but the alpha is a timeline tweenable property as well, so if in your animation you were changing the alpha, how would you expect Flash to behave?

sberry
  • 128,281
  • 18
  • 138
  • 165
-2

It works on my system. You must have something else wrong. Check well.

vulkanino
  • 9,074
  • 7
  • 44
  • 71