AS3>按顺序显示数组图像的按钮?
制作一个按钮来根据图像在数组中的位置按顺序显示图像有多难?
我需要这个用于下一个和上一个按钮。检查下面的数组。
数组:
private var images:Array = ["Layer_1.jpg", "Layer_2.jpg", "Layer_3.jpg", "Layer_4.jpg", "Layer_5.jpg", "Layer_6.jpg", "Layer_7.jpg", "Layer_8.jpg"];
按钮:
private var triangleButton:triangle = new triangle;
//to call the function slideGames
triangleButton.addEventListener(MouseEvent.CLICK, slideGames);
加载器:
private var loader:Loader = new Loader();
完整代码:
package {
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class play extends MovieClip {
private var loader:Loader = new Loader();
private var images:Array = ["Layer_1.jpg", "Layer_2.jpg", "Layer_3.jpg", "Layer_4.jpg", "Layer_5.jpg", "Layer_6.jpg", "Layer_7.jpg", "Layer_8.jpg"];
private var triangleButton:triangle = new triangle;
public function play() {
loader.load(new URLRequest("img/Layer_1.jpg"));
addChild(loader);
addChild(triangleButton);
triangleButton.x = 600;
triangleButton.y = 200;
triangleButton.addEventListener(MouseEvent.CLICK, slideGames);
function slideGames(event:MouseEvent):void
{
}
}
}}
How hard it is to make a button to display images in order, acording to their position inside an array?
I need this for the NEXT and PREVIOUS buttons. Check the array below.
Array:
private var images:Array = ["Layer_1.jpg", "Layer_2.jpg", "Layer_3.jpg", "Layer_4.jpg", "Layer_5.jpg", "Layer_6.jpg", "Layer_7.jpg", "Layer_8.jpg"];
Button:
private var triangleButton:triangle = new triangle;
//to call the function slideGames
triangleButton.addEventListener(MouseEvent.CLICK, slideGames);
Loader:
private var loader:Loader = new Loader();
Full Code:
package {
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class play extends MovieClip {
private var loader:Loader = new Loader();
private var images:Array = ["Layer_1.jpg", "Layer_2.jpg", "Layer_3.jpg", "Layer_4.jpg", "Layer_5.jpg", "Layer_6.jpg", "Layer_7.jpg", "Layer_8.jpg"];
private var triangleButton:triangle = new triangle;
public function play() {
loader.load(new URLRequest("img/Layer_1.jpg"));
addChild(loader);
addChild(triangleButton);
triangleButton.x = 600;
triangleButton.y = 200;
triangleButton.addEventListener(MouseEvent.CLICK, slideGames);
function slideGames(event:MouseEvent):void
{
}
}
}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
基本思想是保留一个指向您要显示的下一个图像的整数指针。当显示下一个图像时,增加该指针。如果它超过了图像源数组的长度,请将其重置为 0。
该指针从 -1 开始,因此第一次递增时它的值为 0。
您应该能够轻松处理前一种情况 - 只需减少指针,而不是检查它是否大于数组长度,而是检查它是否小于零并将其设置为 images.length-1。
Try this:
The basic idea is to keep an integer pointer to the next image you want to display. When you display the next image, increment this pointer. If it exceeds the length of the image source array, reset it to 0.
This pointer starts at -1 so that the first time it is incremented it has the value 0.
You should be able to handle the previous case easily -- just decrease the pointer and instead of checking if it is bigger than the array length, check if it is less than zero and set it to images.length-1.