Actionscript 3 as3 Greensock throwProps加载子项时出错
我对Greensock在电影剪辑中的孩子们有意见。我知道这些行有错误Actionscript 3 as3 Greensock throwProps加载子项时出错,actionscript-3,loading,children,gsap,Actionscript 3,Loading,Children,Gsap,我对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
// 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);
导入flash.filesystem.File;
导入com.greensock.*;
导入com.greensock.com;
导入com.greensock.plugins.*;
导入flash.geom.Rectangle;
导入flash.utils.getTimer;
导入flash.events.MouseEvent;
导入flash.text.*;
导入flash.display.*;
TweenPlugin.activate([ThrowPropsPlugin]);
var folderLanguages:File=File.applicationDirectory.resolvePath(“语言”);
var availlanguang:Array=folderLanguages.getDirectoryListing();
var-Lang:数组;
路径:数组;
var标志按钮:MovieClip;
var myFlagInfo:LoaderInfo;
var-myFlag:Loader;
函数getLang(evt:事件)
{
Lang=新数组();
LangPath=新数组();
对于(变量i:uint=0;ibounds.top){
mc.y=(y+bounds.top)*0.5;
}否则如果(y50){
y2=y1;
t2=t1;
y1=mc.y;
t1=t;
}
event.updateAfterEvent();
}
函数mouseHandler(事件:MouseEvent):void{
mc.stage.removeEventListener(MouseEvent.MOUSE\u UP,mouseHandler);
mc.stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
变量时间:Number=(getTimer()-t2)/1000;
var yVelocity:数字=(mc.y-y2)/时间;
ThrowPropsPlugin.to(mc,{throwProps:{
y:{velocity:yVelocity,max:bounds.top,min:bounds.top-yOverlap,阻力:300}
},onUpdate:blitMask.update,ease:Strong.easeOut
}, 10, 0.3, 1);
}
B1.addEventListener(MouseEvent.CLICK,getLang);
B2.addEventListener(MouseEvent.CLICK,displayFlags);
你说他们走了是什么意思?空对象?你看不见他们吗?你跟踪过它的坐标吗?这里有一个链接,指向我的项目的zip,没有greensock插件。我需要设法让throwprops连接到flagButton。