PDA

View Full Version : weird (parent as MovieClip)


opencity
01-19-2008, 09:12 PM
Just a warning -
Auto Format seems to be changing the
(parent as MovieClip)
to
parent as MovieClip
(removing the parens and adding spaces?!?)
and errors ensue.
A WTF but changing them back is all that's needed.

Scottae
01-19-2008, 11:55 PM
So is there a question or are you just point this out?

opencity
01-20-2008, 12:39 AM
Sorry if that's against forum rules.

I'm just pointing it out as it was a couple of minutes of angst on my part.
(unless there's an interesting workaround - I didn't look after figuring it out but the prefs don't seem to address this)

Scottae
01-20-2008, 01:04 AM
I don't get that problem

import flash.display.*;

var main:MovieClip = (this as MovieClip);
trace(main);

var s:Sprite = new Sprite();
main.addChild(s);
s.graphics.lineStyle(15, 0xFF0000, 1);
s.graphics.lineTo(0.15, 0);
s.x = s.y = 20;
trace(s);

var p:MovieClip = (s.parent as MovieClip);
trace(p);

opencity
01-21-2008, 08:18 AM
On my box the top function loses the parens on Auto Format every time and the bottom function doesn't.
My thinking is MovieClip(parent) might be the better method for left side of =

os x 10.5.1
CS 9.0
----------------
package {
public class testMove {
public function testMove(event:MouseEvent) {
(parent as MovieClip).testMove(dur.text, tim.text);
}
public function other(event:MouseEvent) {
var p:MovieClip = (s.parent as MovieClip);
}
}
}

Scottae
01-21-2008, 12:20 PM
You should do this instead.....I think:

package {
public class testMove {
public function testMove(event:MouseEvent) {
var p:MovieClip = parent as MovieClip;
p.testMove(dur.text, tim.text);
}
public function other(event:MouseEvent) {
var p:MovieClip = (s.parent as MovieClip);
}
}
}

opencity
01-21-2008, 07:16 PM
Assign to a variable first.
That works! (sort of qualifies as a d'oh)
Thanks!

Scottae
01-21-2008, 10:14 PM
Assign to a variable first.
That works! (sort of qualifies as a d'oh)
Thanks!

I think it's good practice to do that. It makes things much easier to read, there is less typing, and you don't get the errors.