Hey guys, just signed up and this is my first post. Been running into trouble with the provided code from “Learning Actionscript 3.0: A Beginner’s Guide” by Shupe and Rosser.
When using the example files from the website, I changed the property of setChildIndex. Here is the original code:
[COLOR=“DarkRed”]
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Zsorting extends MovieClip {
public function Zsorting() {
this.addEventListener(MouseEvent.MOUSE_OVER, onBringToTop, false, 0, true);
}
private function onBringToTop(evt:MouseEvent):void {
var folder:MovieClip = evt.target as MovieClip;
setChildIndex(folder, numChildren - 1);
}
}
}
[/COLOR]
***Notice setChildIndex(folder, numChildren-1);
I then replaced folder with evt.target and the whole thing WORKS.
Now I tried creating my own flash file and populating it with different movie clips. Here is the code that works:
[COLOR=“DarkRed”]
package {
import flash.display.*;
import flash.events.*;
public class main_swapChildren extends MovieClip {
public function main_swapChildren() {
this.addEventListener(MouseEvent.MOUSE_OVER, onBringToTop, false, 0, true);
function onBringToTop(evt:MouseEvent):void {
var folder:MovieClip = evt.target as MovieClip;
var folder02:MovieClip = evt.target as MovieClip;
var base_folder:MovieClip = evt.target as MovieClip;
setChildIndex(base_folder, numChildren-1); //--> don't know why but the object base_folder can be
//--> any of the declared movie clips, ie folder or folder02
}
}
}
}
[/COLOR]
Notice setChildIndex(base_folder, numChildren-1); I can replace base_folder with any one of the declared movie clips such as folder and folder02AND IT WORKS.
Here’s the problem, using my new flash file, changing setChildIndex(base_folder with setChildIndex(evt.target [COLOR=“Blue”](which is similar to what I did with the file provided by the website)[/COLOR] produces this error message:
[COLOR=“DarkRed”]
1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.
Source: setChildIndex(evt.target, numChildren-1);
[/COLOR]
Please help me as this is driving me nuts. The files from the website seem to behave differently from the files I’ve created. And I can’t figure out where I went wrong. Any help would be GREATLY appreciated…