1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| package
{
import mx.core.UIComponent;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.utils.getQualifiedClassName;
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class TestMain extends UIComponent
{
public var loader:Loader;
public function init():void {
loader = new Loader();
loader.contentLoaderInfo.addEventListener("init", onLoad);
loader.contentLoaderInfo.addEventListener("ioError", onError);
loader.load(new URLRequest("TestSwfDansFlex.swf"));
} // end constructor
public function onLoad(aEvent:Event):void {
trace("Fichier chargé");
//aEvent.target.content.name = "SWFloaded";
this.addChild(aEvent.target.content);
trace("Parsing des éléménts disposés sur le Stage:\n");
recursChildren(this.stage, 0, "");
var myRoot1:* = loader.contentLoaderInfo.content;
var myRoot2:* = this.parent["SWFonStage"].content;
trace("Vérification 1: "+myRoot1.clipA.x);
myRoot1.clipA.alpha = .5;
trace("Vérification 2: "+myRoot2.clipB.x);
myRoot2.clipB.alpha = .5;
} // end onLoad
public function onError(aEvent:Event):void {
trace("Erreur de chargement");
} // end onError
public function recursChildren(aContainer:*, aRank:uint, aPath:String):void {
var tab:String = (" ").substr(0, (aRank+1)*3);
trace(tab+"Analyse de l'objet: "+aContainer.name+", type "+getQualifiedClassName(aContainer)+", chemin: "+aPath);
var nChildren:uint;
try {nChildren = aContainer.numChildren} catch (a:*) {
trace(tab+"Cet objet: "+aContainer.name+" n'est pas un DisplayObjectContainer.");
return;
}
for (var u:uint=0; u<nChildren; u++) {
trace(tab+" +"+aContainer.getChildAt(u).name+" --> "+getQualifiedClassName(aContainer.getChildAt(u)));
switch (aContainer.getChildAt(u).name) {
case "clipA": getClip(aContainer.getChildAt(u)); break;
case "clipB": getClip(aContainer.getChildAt(u)); break;
case "clipC": getClip(aContainer.getChildAt(u)); break;
}
recursChildren(aContainer.getChildAt(u), aRank+1, aPath+"."+aContainer.getChildAt(u).name);
}
} // end recursChildren
public function getClip(aClip:MovieClip):void {
aClip.addEventListener("mouseDown", clipMouseDown);
aClip.addEventListener("mouseUp", clipMouseUp);
} // end getClip
public function clipMouseDown(aEvent:MouseEvent):void {
trace("Souris DOWN sur le clip: "+aEvent.target.name);
aEvent.target.alpha -= .4;
} // end clipMouseDown
public function clipMouseUp(aEvent:MouseEvent):void {
trace("Souris UP sur le clip: "+aEvent.target.name);
aEvent.target.alpha += .4;
} // end clipMouseUp
} // end class
} // end package |
Partager