First look at the effect:
http://public.iecn.net/freebrandy/ShowImage/ShowImagesIII.swf
Improvement process
http://public.iecn.net/freebrandy/ShowImage/ShowImages.swf
http://public.iecn.net/freebrandy/ShowImage/ShowImagesII.swf
Source file Download:picchange.rar
As Class Code:
Import Mx.events.EventDispatcher;
Class Showimages extends MovieClip {
private Var Myurl:array; An array that holds the path of a picture
private Var Myinfo:array; An array that holds picture information
private Var Showimagebox:movieclip; Picture Display Area
private var myloading:movieclip//MC for loading pictures
private Var Topmc:movieclip; Top of MC
private Var Buttonmc:movieclip; Bottom MC
private Var Currenttopmc:movieclip; Record the current MC in a higher depth
private var Allowtoplayimage:boolean = true;
private Var _id:number; Timer ID
private var _showtime:number = 3000; Timer time length
private var imageid:number = 0; Save picture ID values when playing automatically
private Var Mymask:movieclip; Mask MC
private Var imagedepth:number=100; Place the depth of the image MC
private var Firstloadimage:boolean = true; Whether to load a picture for the first time
private static var Loadertextformat:textformat = new TextFormat ("Arial", NULL, 0x000000, true);
public Var addeventlistener:function;
public Var removeeventlistener:function;
private Var dispatchevent:function;
private static var _mixin1 = Eventdispatcher.initialize (Showimages.prototype);
Public Function showimages () {
Fscommand ("Allowscale", false);
Fscommand ("ShowMenu", false);
}
Private Function OnLoad (): Void {
Navigate to the original point
_x = _y = 0;
Add a listening event
AddEventListener ("Onphotolistload", this);
Import an XML file that holds pictures
Myurl = new Array ();
MyInfo = new Array ();
var me:object = this;
var my_xml = new XML ();
My_xml.ignorewhite = true;
My_xml.load ("Photolist.xml");
My_xml.onload=function (Success) {
if (success) {
Array Value Added
var xmla:array = this.firstChild.childNodes;
var xmlalen:number = xmla.length;
for (var i = 0; i<xmlalen; i++) {
Me.myUrl.push (Xmla[i].attributes.myurl);
Me.myInfo.push (Xmla[i].attributes.myinfo);
}
Sending an event to itself
Me.dispatchevent ({type: "Onphotolistload", target:this});
}
}
}
Private Function Onphotolistload (): Void {
Set up the MC that put the picture first
Showimagebox = This.createemptymovieclip ("Showimagebox", imagedepth);
myloading = Showimagebox.createemptymovieclip ("myloading", imagedepth+20);
TOPMC = Showimagebox.createemptymovieclip ("TOPMC", imagedepth+10);
topmc._x = 200;
BUTTONMC = Showimagebox.createemptymovieclip ("BUTTONMC", imagedepth);
Import picture (LoadImage is a self-looping function)
LoadImage ();
}
Private Function LoadImage (): Void {
Cancel the timer first
Clearinterval (_id);
Get the object itself for easy access
var thisobject:object = this;
loop control (This method uses the transform depth and then sets the mask)
if (imageID = = myurl.length) imageID = 0;
Do not need to exchange depth when loading pictures for the first time
if (firstloadimage) {
CURRENTTOPMC = TOPMC;
Firstloadimage = false;
}else{
Exchange Depth First
Topmc.swapdepths (BUTTONMC);
And decide who's up there.
if (topmc.getdepth () > Buttonmc.getdepth ()) {
CURRENTTOPMC = TOPMC;
}else{
CURRENTTOPMC = BUTTONMC;
}
}
In the above MC import picture, because the mask is only on the top of the MC
Currenttopmc.loadmovie (Myurl[imageid]);
Trace (Topmc.getdepth ());
imageid++;
Import Pictures
Myloading.onenterframe = function () {
var lb:number = thisObject.currentTopMC.getBytesLoaded ();
var tb:number = ThisObject.currentTopMC.getBytesTotal ();
var percent:number = Math.Round (lb/tb*100);
if (percent = = thisObject.currentTopMC.getBytesLoaded () >100 and thisobject.currenttopmc._height>0) {
Special effects display Pictures
Thisobject.showoff (THISOBJECT.CURRENTTOPMC);
Call Timer control picture Showoff time
thisobject._id = SetInterval (Thisobject, "LoadImage", thisobject._showtime);
Cancel Onenterframe
Delete This.onenterframe;
}
}
}
Private Function Showoff (mc:movieclip): Void {
Mymask = Showimagebox.createemptymovieclip ("Mymask", imagedepth+30);
Give a random mask method (the range of this random number gives itself, the size for all the number of methods and, I give here 5 basic methods, the reader can add)
var myrnd:number = random (5);
Eval ("Showoff_" +myrnd) (Mymask);
Showoff_4 (Mymask);
Speed control
var v:number = 10;
//----------------------------------------------------------------
Method One (top left to bottom right)
function Showoff_0 (mc:movieclip) {
Drawrectangleat (MC);
Mc.onenterframe = function () {
if (_width >= stage.width and _height >= stage.height) Delete this.onenterframe;
_width + V;
_height + V;
}
}
Method Two (left to right)
function Showoff_1 (mc:movieclip) {
Drawrectangleat (MC);
Mc._height = Stage.height;
Mc.onenterframe = function () {
if (_width >= stage.width) Delete this.onenterframe;
_width + V;
}
}
Method Three (top to bottom)
function Showoff_2 (mc:movieclip) {
Drawrectangleat (MC);
Mc._width = Stage.width;
Mc.onenterframe = function () {
if (_height >= stage.height) Delete this.onenterframe;
_height + V;
}
}
Method four (down to top)
function Showoff_3 (mc:movieclip) {
Drawrectangleat (MC);
mc._y = Stage.height;
Mc._width = Stage.width;
Mc.onenterframe = function () {
if (_height >= stage.height) Delete this.onenterframe;
_height + V;
_y = v;
}
}
Method Five (right to left)
function Showoff_4 (mc:movieclip) {
Drawrectangleat (MC);
mc._x = Stage.width;
Mc._height = Stage.height;
Mc.onenterframe = function () {
if (_width >= stage.width) Delete this.onenterframe;
_width + V;
_x = v;
}
}
//--------------------------------------------------------------------------
Function: Draw a rectangle to make a mask of distortion (you can also use Attachmovie to add from the library, so you can do all kinds of shapes.)
I'm emphasizing the script in this example)
function Drawrectangleat (mc:movieclip) {
With (MC) {
LineStyle (0, 0XFFFFFF, 100);
Beginfill (0XFFFFFF);
MoveTo (0, 0);
LineTo (0, 10);
LineTo (10, 10);
LineTo (10, 0);
LineTo (0, 0);
Endfill ();
}
}
Set Mask
Trace (MC);
Mc.setmask (Mymask);
}
Setter method
Public Function set Showtime (I:number): Void {
_showtime = i;
}
}