我正在使用下面的代码,当我“跟踪(TheVar);” 它是空的。有谁知道为什么?
var TheVar:MovieClip;
var myArray:Array = ["TheContent", "TheContent2"];
function RandomM()
{
trace(myArray.length);
var r = Math.round(Math.random() * myArray.length);
trace(myArray[r]);
var TheVar:MovieClip = myArray[r] as MovieClip;
trace(TheVar);
}
RandomM();
更新:
我正在输入完整的代码来展示我正在尝试做的事情
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;
var TheContent:Loader = new Loader();
var TheContent2:Loader = new Loader();
function Load1()
{
TheContent.load(new URLRequest("1.png"));
TheContent.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadContent);
function LoadContent(e:Event)
{
addChild(TheContent);
TheContent.width = ScreenX;
TheContent.height = ScreenY;
Load2()
}
}
function Load2()
{
TheContent2.load(new URLRequest("2.png"));
TheContent2.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadContent);
function LoadContent(e:Event)
{
trace("Jesus");
addChild(TheContent2);
TheContent2.width = ScreenX;
TheContent2.height = ScreenY;
RandomM();
}
}
在函数中RandomM()
,我想将加载器“TheVar”更改为这些数组之一,其中也是加载器。我想最终创建一个补间,它将根据用户的滑动在加载器之间发生变化。
var TheVar:MovieClip;
var myArray:Array = [TheContent, "TheContent2"];
function RandomM()
{
trace(myArray.length);
var r = Math.round(Math.random() * myArray.length);
trace(myArray[r]);
var Base:Class = getDefinitionByName(myArray[r]) as Class;
var TheVar:MovieClip = new Base();
}
Load1();
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);
function fl_SwipeHandler(event:TransformGestureEvent):void
{
switch(event.offsetX)
{
// swiped right
case 1:
{
// Start your custom code
// This example code moves the selected object 200 pixels to the right.
TheVar.x += 200;
// End your custom code
break;
}
// swiped left
case -1:
{
// Start your custom code
// This example code moves the selected object 200 pixels to the left.
TheVar.x -= 200;
// End your custom code
break;
}
}
switch(event.offsetY)
{
// swiped down
case 1:
{
// Start your custom code
// This example code moves the selected object 200 pixels down.
TheVar.y += 200;
// End your custom code
break;
}
// swiped up
case -1:
{
// Start your custom code
// This example code moves the selected object 200 pixels up.
TheVar.y -= 200;
// End your custom code
break;
}
}
}
添加更新以澄清:
我有一个名为 TheContent 的 LOADER:这是代码:
var TheContent:Loader = new Loader();
我想创建几个具有图像和 SWF 内容的“加载器”。然后我想使用 ONE TWEEN 将它们移出屏幕,但通过动态补间,因此它将根据我在该 TWEEN 中制作 MovieClip 的 VAR 移动不同的 LOADERS。要做到这一点,我需要为 TWEEN 制作电影...... 多变的。我认为最好的方法是创建一个包含 LOADERS 的所有名称的数组,然后随机调用它们并在 TWEEN 中移动内容。因此我做了一个数组:
var myArray:Array = ["TheContent", "TheContent2"];
但我根本无法从函数 RandomM(); 中获取随机变量。所以我可以稍后在 TWEEN 中使用它。该加载程序称为“TheVar”;
function RandomM()
{
trace(myArray.length);
var r = Math.round(Math.random() * (myArray.length -1) );
var theMC:String = myArray[r];
TheVar=this[theMC] as MovieClip;
trace(TheVar); //// TO BE USED LATER IN A TWEEN.
/// IT WILL BE ONE TWEEN BUT WILL ANIMATE DIFFERENT MOVIES
}
我希望这是有道理的。