我遇到了有关电影剪辑的 Greensock 显示子项的问题。我知道这些行中有错误
// this works and makes flagButton alpha to .3
// Displays Flags which are children in the button called FlagButton
flagButton.alpha = .3; // works
addChild(mc);
// But if I uncomment this code the flags in my MC are GONE. It doesnt make sense.
/// The MC shows and I can control it via greensock but FLAGS are gone.
//mc.addChild(flagButton);
什么会导致这种情况?我认为这是儿童和显示器的问题。
这是完整的代码:
import flash.filesystem.File;
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.geom.Rectangle;
import flash.utils.getTimer;
import flash.events.MouseEvent;
import flash.text.*;
import flash.display.*;
TweenPlugin.activate([ThrowPropsPlugin]);
var folderLanguages:File = File.applicationDirectory.resolvePath("Languages");
var availLang:Array = folderLanguages.getDirectoryListing();
var Lang:Array;
var LangPath:Array;
var flagButton:MovieClip;
var myFlagInfo:LoaderInfo;
var myFlag:Loader;
function getLang(evt:Event)
{
Lang = new Array();
LangPath = new Array();
for (var i:uint = 0; i < availLang.length; i++)
{
if(availLang[i].isDirectory)
{
//trace(availLang[i].name);// gets the name
Lang.push(availLang[i].name);
LangPath.push(availLang[i].nativePath);
trace(availLang[i].nativePath);// gets the name
}
}
evt.target.visible = false;
}
var Language:MovieClip;
var LangButton:MovieClip;
var flag:Loader;
var fh:Object;
var mc:MovieClip = new MovieClip;
var bounds:Rectangle;;
//setupTextField(mc, bounds);
var blitMask:BlitMask;
bounds = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
var t1:uint, t2:uint, y1:Number, y2:Number, yOverlap:Number, yOffset:Number;
function displayFlags(evt:Event = null)
{
if(!Lang) { return; }
flagButton = new MovieClip();
addChild(flagButton);
//addChild(mc);
for (var i:uint = 0; i < Lang.length; i++)
{
//Language = new MovieClip();
//Language.name = Lang[i];
LangButton = new button01();
LangButton.name = Lang[i];
LangButton.btext.text = Lang[i];
LangButton.y = LangButton.height * i;
LangButton.btext.x = 125;
addChild(LangButton);
flag = new Loader();
flag.load(new URLRequest(LangPath[i]+"/flag.png"));
flag.name = Lang[i];
flag.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedFlag);
function loadedFlag(evt:Event)
{
var fh = flag.getBounds(flag);
trace("FLAG HEIGHT = " + fh);
trace("flag Name: "+ flag.name);
trace(flag);
myFlagInfo = evt.currentTarget as LoaderInfo;
myFlag= myFlagInfo.loader;
myFlag.y = (LangButton.height/2) - (flag.height/2);
}
LangButton.addChild(flag);
flagButton.addChild(LangButton);
}
evt.target.visible = false;
flagButton.alpha = .3;
addChild(mc);
//mc.addChild(flagButton);
//bounds = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
blitMask = new BlitMask(mc, bounds.x, bounds.y, bounds.width, bounds.height, false);
blitMask.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
function mouseDownHandler(event:MouseEvent):void {
TweenLite.killTweensOf(mc);
y1 = y2 = mc.y;
yOffset = this.mouseY - mc.y;
yOverlap = Math.max(0, mc.height - bounds.height);
t1 = t2 = getTimer();
mc.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
mc.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
function mouseMoveHandler(event:MouseEvent):void {
var y:Number = this.mouseY - yOffset;
//if mc's position exceeds the bounds, make it drag only half as far with each mouse movement (like iPhone/iPad behavior)
if (y > bounds.top) {
mc.y = (y + bounds.top) * 0.5;
} else if (y < bounds.top - yOverlap) {
mc.y = (y + bounds.top - yOverlap) * 0.5;
} else {
mc.y = y;
}
blitMask.update();
var t:uint = getTimer();
//if the frame rate is too high, we won't be able to track the velocity as well, so only update the values 20 times per second
if (t - t2 > 50) {
y2 = y1;
t2 = t1;
y1 = mc.y;
t1 = t;
}
event.updateAfterEvent();
}
function mouseUpHandler(event:MouseEvent):void {
mc.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
mc.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
var time:Number = (getTimer() - t2) / 1000;
var yVelocity:Number = (mc.y - y2) / time;
ThrowPropsPlugin.to(mc, {throwProps:{
y:{velocity:yVelocity, max:bounds.top, min:bounds.top - yOverlap, resistance:300}
}, onUpdate:blitMask.update, ease:Strong.easeOut
}, 10, 0.3, 1);
}
B1.addEventListener(MouseEvent.CLICK, getLang);
B2.addEventListener(MouseEvent.CLICK, displayFlags);