问题
My current code that allow application to upload data inside of Excel file into the AIR app is as follows;
import lib.xlsxreader.Worksheet;
import lib.xlsxreader.XLSXLoader;
public class Main extends MovieClip
{
private var fileGet: File = new File();
private var xloader: XLSXLoader = new XLSXLoader();
public function Main()
{
fileGet = File.applicationDirectory;
fileGet.addEventListener(Event.SELECT, selectExcel)
xloader.addEventListener(Event.COMPLETE, uploadComplete);
button.addEventListener(MouseEvent.CLICK, selectFile);
}
private function selectFile(e: MouseEvent): Void
{
fileGet.browseForOpen("Select File");
xloader.load(fileGet.nativePath);
}
private function uploadComplete(e: Event): Void
{
ws = xloader.worksheet("[Name of the worksheet]");
rowStart = 7;
rowEnd = ws.rows;
for (var i = rowStart; i <= rowEnd; i++)
{
//transferring data from excel into sqlite
}
}
}
The code above is not my complete code, I just shorten it to the relevant code. Let me know if you need more information.
Right now the code is transferring data from 30 columns and 1000++ rows from Excel file for about 10 minutes which is kinda slow and make the AIR app appear 'hang' or 'frooze' during uploading.
It come to my attention that I can use Worker API in Actionscript to fasten this process but for the life of me, I can't exactly figuring out how to restructuring my code to allow Worker API in my code.
I have read through example from here, here and here, but I still can't make heads or tails on this issue.
As far as my understanding goes, my code //transferring data from excel into sqlite
should be included in class CountResult from this example...?
Can someone help me on this problem. Take note that I'm a self-learn amateur programmer trying to learn to make dekstop app using Adobe Animate.
来源:https://stackoverflow.com/questions/61153868/using-actionscript-worker-to-loop-function-to-make-it-faster