Two questions about loading and parsing air files

Source: Internet
Author: User

Because it is necessary to drag into the loading price resolution, so the first thought is the air, the code found on the internet is as follows:

Public class darg extends Sprite
{
Public Function darg ()
{
If (stage ){
Creat ();
} Else {
Addeventlistener (event. added_to_stage, creat );
}
}
Private VaR _ sp: SPRITE = new sprite ();
Private VaR _ format: array = [". jpg ",". jpg ",". JPEG ",". JPEG ",". GIF ",". GIF ",". PNG ",". SWF ",". PNG "];
Protected function creat (Event: event = NULL): void
{
_ Sp. Graphics. beginfill (0xff0000, 0.5 );
_ Sp. Graphics. drawrect (0, 0, stage. stagewidth, stage. stageheight );
_ Sp. Graphics. endfill ();
Addchild (_ Sp );
Stage. addeventlistener (nativedragevent. native_drag_enter, ondrop );
Stage. addeventlistener (nativedragevent. native_drag_drop, ondrop );
}

Private var Loader: loader = new loader;
Protected function ondrop (Event: nativedragevent): void
{
// Obtain the dragged file in array format, and specify that the dragged data is in file array format.
VaR files: array = event. clipboard. getdata (clipboardformats. file_list_format) as array;
// Obtain the first file to be dragged.
Var file: file = file (files [0]);
Switch (event. Type ){
Case nativedragevent. native_drag_enter:
If (_ format. indexof (file. Type )! =-1 ){
Nativedragmanager. acceptdragdrop (this );
}
Break;
Case nativedragevent. native_drag_drop:
If (_ format. indexof (file. Type )! =-1 ){
// Delete the uploaded Image
Loader. Unload ();
// Load the dragged Image
Loader. Load (New URLRequest (file. url ));
Removechild (_ Sp );
Addchild (loader );
}
Break;
}
}

 

Two issues to be aware:

1. There must be something on the stage, that is why the sprite should be added to the Code;

2. addchild is required, but not stage. addchild is added to the current scenario, rather than to the underlying stage. If you can listen to native_drag_enter on the stage, but there is no native_drag_drop event, you have not studied the specific cause. If you know, you can post it.

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.