我正在尝试使用循环更改各种精灵的属性。但是,我收到此错误消息,但我不知道如何修复它:ReferenceError: Error #1069: Property transform not found on String and there is no default value。在 LevelScreen/LevelUnlockedColor()[/Users/jakub/Cloud Drive/Documents/JH_WORK/IMPOSSIBLE_SCREEN/LevelScreen.as:232] 在 LevelScreen()[/Users/jakub/Cloud Drive/Documents/JH_WORK/IMPOSSIBLE_SCREEN/LevelScreen.as: 31] 在函数/MainMenu/LoadMenu/taphandler2Click()[/Users/jakub/Cloud Drive/Documents/JH_WORK/IMPOSSIBLE_SCREEN/MainMenu.as:94]
这是代码:
public function LevelUnlockedColor()
{
mySharedObject.data.Unlocked = 3;
mySharedObject.flush();
var boxes:Array = [];
for (var i:int = 0; i<mySharedObject.data.Unlocked; i++)
{
var spriteName:Sprite = new Sprite();
spriteName.name = "LVL" + i;// "sprite_0" "sprite_1" ...
boxes[i] = spriteName.name;
boxes.push(spriteName);
var trans:ColorTransform = boxes[i].transform.colorTransform;
trans.color = uint(0xd982ab);
boxes[i].transform.colorTransform = trans;
trace(boxes[i]); //output LVL0, LVL1, LVL2
}
}
谢谢你。
这是其余的代码:
package
{
import flash.display.*;
import flash.ui.*;
import flash.events.*;
import flash.filesystem.*;
import flash.net.URLLoader;
import flashx.textLayout.accessibility.TextAccImpl;
import flash.net.*;
import flash.geom.*;
public class LevelScreen extends Sprite
{
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
public var LVL1:Sprite = new Sprite ;
public var LVL2:Sprite = new Sprite ;
public var LVL3:Sprite = new Sprite ;
public var LVL4:Sprite = new Sprite ;
public var LVL5:Sprite = new Sprite ;
public var LVL6:Sprite = new Sprite ;
public var mySharedObject:SharedObject = SharedObject.getLocal("LevelsSaved");
public function LevelScreen()
{
DrawLevels();
LevelUnlockedColor();
var PauseBtn:MainMenu = new MainMenu();
PauseBtn.GamePaused();
addChild(PauseBtn);
LVL1.addEventListener(TouchEvent.TOUCH_TAP,taphandler1);
LVL2.addEventListener(TouchEvent.TOUCH_TAP,taphandler2);
LVL2.addEventListener(MouseEvent.CLICK,taphandler2Click);
LevelCheck();
}
public function DrawLevels()
{
LVL1.graphics.beginFill(0xe6e7e8);
LVL1.graphics.drawRect(50,90,260,260);
addChild(LVL1);
LVL2.graphics.beginFill(0xd1d3d4);
LVL2.graphics.drawRect(330,90,260,260);
addChild(LVL2);
LVL3.graphics.beginFill(0xbcbec0);
LVL3.graphics.drawRect(50,370,260,260);
addChild(LVL3);
LVL4.graphics.beginFill(0xa7a9ac);
LVL4.graphics.drawRect(330,370,260,260);
addChild(LVL4);
LVL5.graphics.beginFill(0x939598);
LVL5.graphics.drawRect(50,650,260,260);
addChild(LVL5);
LVL6.graphics.beginFill(0x808285);
LVL6.graphics.drawRect(330,650,260,260);
addChild(LVL6);
}
public function HideAll()
{
removeChild(LVL1);
removeChild(LVL2);
removeChild(LVL3);
removeChild(LVL4);
removeChild(LVL5);
removeChild(LVL6);
}
public function taphandler1(event:TouchEvent):void
{
var LoadLVL1:LEVEL_01 = new LEVEL_01();
LoadLVL1.drawLVL_01();
addChild(LoadLVL1);
HideAll();
}
public function taphandler2(event:TouchEvent):void
{
if (mySharedObject.data.Unlocked >= 1)
{
var LoadLVL2:LEVEL_02 = new LEVEL_02();
LoadLVL2.LoadLevel2();
addChild(LoadLVL2);
HideAll();
}
else
{
trace("LEVEL 02 is locked");
}
}
public function taphandler2Click(event:MouseEvent):void
{
if (mySharedObject.data.Unlocked >= 1)
{
var LoadLVL2:LEVEL_02 = new LEVEL_02();
LoadLVL2.LoadLevel2();
addChild(LoadLVL2);
HideAll();
}
else
{
trace("LEVEL 02 is locked");
}
}
public function LevelCheck()
{
if (mySharedObject.data.Unlocked >= 1)
{
trace("some levels unlocked already " + mySharedObject.data.Unlocked);
}
else
{
mySharedObject.data.Unlocked = 0;
mySharedObject.flush();
trace("new sharedobject created " + mySharedObject.data.Unlocked);
}
}
public function LevelUnlockedColor()
{
mySharedObject.data.Unlocked = 3;
mySharedObject.flush();
var boxes:Array = [];
for (var i:int = 1; i<mySharedObject.data.Unlocked; i++)
{
var spriteName:Sprite = new Sprite();
spriteName.name = "LVL" + i;// LVL0 , LVL1 ...
boxes[i] = spriteName;
//boxes.push(spriteName);
var trans:ColorTransform = boxes[i].transform.colorTransform;
trans.color = uint(0xd982ab);
boxes[i].transform.colorTransform = trans;
addChild(boxes[i]);
trace(boxes[i].name);//output LVL0, LVL1, LVL2
trace(trans);
}
}
}
}