强制屏幕重绘而不是使用removeChild()然后addChild()来更新图像?
这是我创建的一些代码作为另一个问题的答案。它将库项目从库中拉出,并以编程方式将其放在舞台上。没什么大不了的,除了为了让屏幕上显示的图像实际更新,我必须删除Child(),然后用addChild()将其返回。还有其他方法可以强制屏幕重画吗?
var currentImage:int = 1;
var MAX_IMAGES:int = 3;
MC_prevButton.addEventListener(MouseEvent.CLICK, goBack);
MC_nextButton.addEventListener(MouseEvent.CLICK, goForward);
var imageClip:MovieClip = new Image_1();
var thumbClip:MovieClip = new Thumb_1();
imageClip.x = thumbClip.x = stage.stageWidth/2;
imageClip.y = thumbClip.y = stage.stageHeight/2;
addChildAt(thumbClip, 0);
addChildAt(imageClip, 1);
setImages(currentImage);
function goBack(event:MouseEvent):void {
if (currentImage) currentImage--;
setImages(currentImage);
}
function goForward(event:MouseEvent):void {
if (currentImage < MAX_IMAGES) currentImage++;
setImages(currentImage);
}
function setImages(imageNumber){
trace("Setting image number: " + imageNumber);
var LibraryImage:Class = getDefinitionByName("Image_" + imageNumber) as Class;
if (LibraryImage){
removeChild(imageClip);
imageClip = new LibraryImage();
addChildAt(imageClip, 1);
}
var LibraryThumb:Class = getDefinitionByName("Thumb_" + imageNumber) as Class;
if (LibraryThumb){
removeChild(thumbClip);
thumbClip = new LibraryThumb();
addChildAt(thumbClip, 0);
}
imageClip.x = thumbClip.x = stage.stageWidth/2;
imageClip.y = thumbClip.y = stage.stageHeight/2;
}
请注意,在此示例中,此代码位于时间线的第 1 帧上,并且它是一个 1 帧 FLA 文件
Here's some code I created as an answer to another question. It pulls a library item out of the library and puts it on stage programmatically. No big deal, except that in order to get the image displayed on the screen to actually update, I had to removeChild() and then addChild() it back. Is there another way to force the screen to redraw?
var currentImage:int = 1;
var MAX_IMAGES:int = 3;
MC_prevButton.addEventListener(MouseEvent.CLICK, goBack);
MC_nextButton.addEventListener(MouseEvent.CLICK, goForward);
var imageClip:MovieClip = new Image_1();
var thumbClip:MovieClip = new Thumb_1();
imageClip.x = thumbClip.x = stage.stageWidth/2;
imageClip.y = thumbClip.y = stage.stageHeight/2;
addChildAt(thumbClip, 0);
addChildAt(imageClip, 1);
setImages(currentImage);
function goBack(event:MouseEvent):void {
if (currentImage) currentImage--;
setImages(currentImage);
}
function goForward(event:MouseEvent):void {
if (currentImage < MAX_IMAGES) currentImage++;
setImages(currentImage);
}
function setImages(imageNumber){
trace("Setting image number: " + imageNumber);
var LibraryImage:Class = getDefinitionByName("Image_" + imageNumber) as Class;
if (LibraryImage){
removeChild(imageClip);
imageClip = new LibraryImage();
addChildAt(imageClip, 1);
}
var LibraryThumb:Class = getDefinitionByName("Thumb_" + imageNumber) as Class;
if (LibraryThumb){
removeChild(thumbClip);
thumbClip = new LibraryThumb();
addChildAt(thumbClip, 0);
}
imageClip.x = thumbClip.x = stage.stageWidth/2;
imageClip.y = thumbClip.y = stage.stageHeight/2;
}
Note that in this example, this code is on frame 1 of the timeline, and that it's a 1-frame FLA file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在前进和后退方法的末尾调用 updateAfterEvent() :
Try calling updateAfterEvent() at the end of your forward and back methods: