Hello to all
I have 2 movieclips on stage with instance names: green & orange.
I am using this code to timeline frame 1 to bring forward each item is clicked:
MovieClip.prototype.bringForward = function():void{
var currentDepth = this.parent.getChildIndex(this);
if(currentDepth<this.parent.numChildren-1){
this.parent.setChildIndex(this, currentDepth+1);
}
}
green.addEventListener(MouseEvent.MOUSE_UP, clicked);
orange.addEventListener(MouseEvent.MOUSE_UP, clicked);
function clicked(e:MouseEvent){
e.target.bringForward();
}
Can anybody tell me how to load this from an external .as file in this:
package {
public class Main {
public function Main() {
}
}
}
I tried a lot of times but i didn’t had any luck.
I tried this:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.accessibility.AccessibilityProperties;
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.KeyboardEvent;
public class Main {
public function Main() {
addListeners();
}
MovieClip.prototype.bringForward = private final function():void{
var currentDepth = this.parent.getChildIndex(this);
if(currentDepth<this.parent.numChildren-1){
this.parent.setChildIndex(this, currentDepth+1);
}
}
private final function addListeners():void
{
green.addEventListener(MouseEvent.MOUSE_UP, clicked);
orange.addEventListener(MouseEvent.MOUSE_UP, clicked);
}
private final function clicked(e:MouseEvent)
{
e.target.bringForward();
}
}
}
Don’t use the prototype thing. Make a function on the class like this: