【发布时间】:2012-04-03 16:57:27
【问题描述】:
我有一个在屏幕上绘制矩形的函数(请参阅 createInfoPanel())
在绘制矩形时,我在其上添加了 2 个文本字段。
但正如您可能猜到的那样,它会立即添加这些内容。
我想延迟添加这些文本字段,然后我想在一段时间后删除这些面板。
问题是,当我设置间隔或计时器时,它们在我使用一次后将无法工作(我必须通过清除/删除来停止它们,它没有再次设置它们)。
由于每次图像更改时都会创建我的面板,因此每次图像更改时我都需要它们工作。
所以,我有两个问题:
1- 每次我的 createInfoPanel() 函数工作时如何重新设置间隔?设置和澄清一次后将不再起作用。
2- 你可以看到 infoPanel.addChild(titleField); addInfoPanel() 函数中的行。我怎样才能在这里制作流畅的动画?我的意思是,文字出现缓慢?
提前致谢。
public class ImageRotator extends Sprite
{
private var ... ; //Some variables
public function ImageRotator(xmlPath:String = "images.xml", interval:int = 8301):void
{
timer = new Timer(interval);
loadXML(xmlPath);
}
private function loadXML(file:String):void
{
urlLoader = new URLLoader(new URLRequest(file));
urlLoader.addEventListener(Event.COMPLETE, parseXML);
}
private function parseXML(e:Event):void
{
xml = new XML(e.target.data);
loadImages();
}
private function loadImages():void
{
for (var i:int = 0; i < xml.children().length(); i++)
{
var loader:Loader = new Loader();
loader.load(new URLRequest(xml.children()[i].@src));
imagesVector.push(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, sortImages);
}
}
private function sortImages(e:Event):void
{
imagesCounter++;
for (var i:int = 0; i < imagesVector.length; i++)
{
imagesVector.reverse();
addChild(imagesVector[i]);
}
//I have only 3 images, I needed to set indexes because
//they were covering each other
this.setChildIndex(imagesVector[2], 0);
this.setChildIndex(imagesVector[1], 0);
this.setChildIndex(imagesVector[0], 0);
if (imagesCounter == imagesVector.length)
{
createInfoPanel();
timer.addEventListener(TimerEvent.TIMER, autoChange);
timer.start();
}
}
private function createInfoPanel():void
{
infoPanel.graphics.beginFill(0x000000, 0.0);
infoPanel.graphics.drawRect(0, 0, 967, 138);
infoPanel.graphics.endFill();
////Here I want to run addInfoPanel() function with 2 seconds delay,
////After it starts, I want to run removeInfoPanel() function with 2 more seconds delay
addChild(infoPanel);
}
private function addInfoPanel():void {
titleField.text = xml.children()[infoCounter]. @ title;
titleField.x = 425;
titleField.y = 0;
description.text = xml.children()[infoCounter]. @ description;
description.x = 427;
description.y = 26;
infoPanel.y = 300;
infoPanel.addChild(titleField);
infoPanel.addChild(description);
}
private function removeInfoPanel():void {
infoPanel.removeChild(titleField);
infoPanel.removeChild(description);
}
private function addActions():void
{
//Some function
}
private function changeImage(e:MouseEvent):void
{
//Image changing function
}
private function changeDepth(e:TweenEvent):void
{
//Some function
}
private function autoChange(e:TimerEvent):void
{
//Some function
}
}
编辑:我过去是如何处理间隔的:
private function createInfoPanel():void
{
//lines above code sample
intervalInfoPanel = setInterval(addInfoPanel,2000);
addChild(infoPanel);
}
private function addInfoPanel():void {
//lines above code sample
clearInterval(intervalInfoPanel);
intervalInfoPanelRemove = setInterval(removeInfoPanel,3500);
}
private function removeInfoPanel():void {
//lines above code sample
clearInterval(intervalInfoPanelRemove);
}
【问题讨论】:
标签: actionscript-3 flash animation actionscript