As.2 flash image loading effect

Source: Internet
Author: User
Tags addchild

Package {
Import flash. display. sprite;
Import flash. events. event;
Import flash. events. mouseevent;
Import flash. events. progressevent;
Import flash. display. bitmap;
Import flash. display. bitmapdata;
Import flash. display. simplebutton;
Import flash. display. loader;
Import flash.net. urlloader;
Import flash.net. urlrequest;
Import fl. transitions. tween;
Import fl. transitions. easing. elastic;
Public class sampleshowpic extends sprite {
Private var page: uint;
Private var size: uint;
Private var total: uint;
Private var posx: number;
Private var posy: number;
Private var pos_sprite: sprite;
Private var thuns_sprite: sprite;
Private var show_bitmap: bitmap;
Private var list_xml: xml;
Private var xml_loader: urlloader;
Private var start_ B: boolean;
Public function sampleshowpic (): void {
Init ();
  }
Private function init (): void {
Page = 1;
Size = 4;
Show_bitmap = new bitmap;
Xml_loader = new urlloader;
Thuns_sprite = new sprite;
Addchild (thuns_sprite );
Xml_loader.addeventlistener (event. complete, onxmlloadcomplete );
Xml_loader.load (new urlrequest ("teamshow. xml "));
Prev_btn.addeventlistener (mouseevent. click, onbtnclick );
Next_btn.addeventlistener (mouseevent. click, onbtnclick );
  }
Private function onxmlloadcomplete (_ evt: event): void {
List_xml1_xml(_evt.tar get. data );
Total = list_xml.children (). length ();
Show_func ();
  }
Private function show_func (): void {
Removechild (thuns_sprite );
Thuns_sprite = new sprite;
Addchild (thuns_sprite );
For (var p: uint = 0; p <size; p ++ ){
Var _ p: uint = (page-1) * size + p;
If (_ p> = total ){
Return;
    }
Var _ info: infosprite = new infosprite;
_ Info. x = 442, _ info. y = p * 110 + 80;
_ Info. time_txt.text = list_xml.content [_ p]. time;
_ Info. titl_txt.text = list_xml.content [_ p]. casetitle;
Loadpic_func (list_xml.content [_ p]. url, string (p ));
Thuns_sprite.addchild (_ info );
   }
  }
Private function loadpic_func (_ str: string, _ n: string): void {
Var _ loaderoader = new loader;
_ Loader. contentloaderinfo. addeventlistener (event. complete, onpicloadcomplete );
_ Loader. contentloaderinfo. addeventlistener (progressevent. progress, onpicloadprogress );
_ Loader. load (new urlrequest (_ str ));
_ Loader. name = _ n;
  }
Private function onpicloadprogress (_ evtrogressevent): void {
Trace ("pro =" + _ evt. bytesloaded/_ evt. bytestotal * 100 );
  }
Private function onpicloadcomplete (_ evt: event): void {
Var _ n: uint=uint(_evt.tar get. loader. name );
Var _ pic: bitmap=_evt.tar get. content as bitmap;
_ Pic. width = 96;
_ Pic. height = 56;
Var _ sprite: sprite = new sprite;
_ Sprite. x = 442;
_ Sprite. y = _ n * 110 + 80;
_ Sprite. addchild (_ pic );
_ Sprite. buttonmode = true;
_ Sprite. addeventlistener (mouseevent. click, onpicclick );
! Start_ B & (start_ B = true) & _ sprite. dispatchevent (new mouseevent (mouseevent. click ));
Thuns_sprite.addchild (_ sprite );
  }
Private function onpicclick (_ evt: mouseevent): void {
Var _ sprite: sprite+_evt.tar get as sprite;
Var _ pic: bitmap = _ sprite. getchildat (0) as bitmap;
Show_bitmap.bitmapdata = _ pic. bitmapdata. clone ();
If (pos_sprite ){
Var _ tweenpx: tween = new tween (pos_sprite, "x", elastic. easeo tutorial ut, pos_sprite.x, posx, 18, false );
Var _ tweenpy: tween = new tween (pos_sprite, "y", elastic. easeout, pos_sprite.y, posy, 18, false );
   }
Posx = _ sprite. x, posy = _ sprite. y, pos_sprite = _ sprite;
Var _ tweenx: tween = new tween (_ sprite, "x", elastic. easeout, posx, 217,18, false );
Var _ tweeny: tween = new tween (_ sprite, "y", elastic. easeout, posy, 245,18, false );
Var x_tween: tween = new tween (show_bitmap, "x", elastic. easeout, 217,22, 18, false );
Var y_tween: tween = new tween (show_bitmap, "y", elastic. easeout, 245,20, 18, false );
Var w_tween: tween = new tween (show_bitmap, "width", elastic. easeout, 96,390, 18, false );
Var h_tween: tween = new tween (show_bitmap, "height", elastic. easeout, 56,470, 18, false );
Addchild (show_bitmap );
  }
Private function onbtnclick (_ evt: mouseevent): void {
Var _ btn: simplebutton=_evt.tar get as simplebutton;
Switch (_ btn ){
Case prev_btn:
If (page> 0 ){
Page --;
Show_func ();
     }
Break;
Case next_btn:
If (page <math. ceil (total/size )){
Page ++;
Show_func ();
     }
Break;
   }
  }
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.