Skip to content

Commit

Permalink
easy AS Workers
Browse files Browse the repository at this point in the history
  • Loading branch information
myflashlab committed Jan 28, 2016
1 parent 0932d92 commit 96f069a
Show file tree
Hide file tree
Showing 300 changed files with 18,973 additions and 79 deletions.
17 changes: 0 additions & 17 deletions .gitattributes

This file was deleted.

62 changes: 0 additions & 62 deletions .gitignore

This file was deleted.

94 changes: 94 additions & 0 deletions FD/AS-Workers.as3proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<project version="2">
<!-- Output SWF options -->
<output>
<movie outputType="Application" />
<movie input="" />
<movie path="bin\AS-Workers.swf" />
<movie fps="30" />
<movie width="800" />
<movie height="600" />
<movie version="19" />
<movie minorVersion="0" />
<movie platform="Flash Player" />
<movie background="#FFFFFF" />
<movie preferredSDK="Flex 4.6.0, AIR 19.0;4.6.0, 19.0;" />
</output>
<!-- Other classes to be compiled into your SWF -->
<classpaths>
<class path="src" />
</classpaths>
<!-- Build options -->
<build>
<option accessible="False" />
<option advancedTelemetry="False" />
<option allowSourcePathOverlap="False" />
<option benchmark="False" />
<option es="False" />
<option inline="False" />
<option locale="" />
<option loadConfig="" />
<option optimize="True" />
<option omitTraces="True" />
<option showActionScriptWarnings="True" />
<option showBindingWarnings="True" />
<option showInvalidCSS="True" />
<option showDeprecationWarnings="True" />
<option showUnusedTypeSelectorWarnings="True" />
<option strict="True" />
<option useNetwork="True" />
<option useResourceBundleMetadata="True" />
<option warnings="True" />
<option verboseStackTraces="False" />
<option linkReport="" />
<option loadExterns="" />
<option staticLinkRSL="True" />
<option additional="-swf-version=24" />
<option compilerConstants="" />
<option minorVersion="" />
</build>
<!-- SWC Include Libraries -->
<includeLibraries>
<!-- example: <element path="..." /> -->
</includeLibraries>
<!-- SWC Libraries -->
<libraryPaths>
<!-- example: <element path="..." /> -->
</libraryPaths>
<!-- External Libraries -->
<externalLibraryPaths>
<!-- example: <element path="..." /> -->
</externalLibraryPaths>
<!-- Runtime Shared Libraries -->
<rslPaths>
<!-- example: <element path="..." /> -->
</rslPaths>
<!-- Intrinsic Libraries -->
<intrinsics>
<!-- example: <element path="..." /> -->
</intrinsics>
<!-- Assets to embed into the output SWF -->
<library>
<!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
</library>
<!-- Class files to compile (other referenced classes will automatically be included) -->
<compileTargets>
<compile path="src\Main.as" />
</compileTargets>
<!-- Paths to exclude from the Project Explorer tree -->
<hiddenPaths>
<hidden path="obj" />
</hiddenPaths>
<!-- Executed before build -->
<preBuildCommand />
<!-- Executed after build -->
<postBuildCommand alwaysRun="False" />
<!-- Other project options -->
<options>
<option showHiddenPaths="False" />
<option testMovie="Default" />
<option testMovieCommand="" />
</options>
<!-- Plugin storage -->
<storage />
</project>
Binary file added FD/bin/AS-Workers.swf
Binary file not shown.
50 changes: 50 additions & 0 deletions FD/obj/AS-WorkersConfig.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!--This Adobe Flex compiler configuration file was generated by a tool.-->
<!--Any modifications you make may be lost.-->
<flex-config>
<target-player>19.0</target-player>
<benchmark>false</benchmark>
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<compiler>
<define append="true">
<name>CONFIG::debug</name>
<value>false</value>
</define>
<define append="true">
<name>CONFIG::release</name>
<value>true</value>
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'1/29/2016'</value>
</define>
<define append="true">
<name>CONFIG::air</name>
<value>false</value>
</define>
<define append="true">
<name>CONFIG::mobile</name>
<value>false</value>
</define>
<define append="true">
<name>CONFIG::desktop</name>
<value>false</value>
</define>
<optimize>true</optimize>
<omit-trace-statements>true</omit-trace-statements>
<verbose-stacktraces>false</verbose-stacktraces>
<source-path append="true">
<path-element>E:\gitHub\easyAS-Worker\FD\src</path-element>
<path-element>C:\Program Files (x86)\FlashDevelop\Library\AS3\classes</path-element>
</source-path>
</compiler>
<file-specs>
<path-element>E:\gitHub\easyAS-Worker\FD\src\Main.as</path-element>
</file-specs>
<default-background-color>#FFFFFF</default-background-color>
<default-frame-rate>30</default-frame-rate>
<default-size>
<width>800</width>
<height>600</height>
</default-size>
</flex-config>
50 changes: 50 additions & 0 deletions FD/obj/AS-WorkersConfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!--This Adobe Flex compiler configuration file was generated by a tool.-->
<!--Any modifications you make may be lost.-->
<flex-config>
<target-player>19.0</target-player>
<benchmark>false</benchmark>
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<compiler>
<define append="true">
<name>CONFIG::debug</name>
<value>false</value>
</define>
<define append="true">
<name>CONFIG::release</name>
<value>true</value>
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'1/29/2016'</value>
</define>
<define append="true">
<name>CONFIG::air</name>
<value>false</value>
</define>
<define append="true">
<name>CONFIG::mobile</name>
<value>false</value>
</define>
<define append="true">
<name>CONFIG::desktop</name>
<value>false</value>
</define>
<optimize>true</optimize>
<omit-trace-statements>true</omit-trace-statements>
<verbose-stacktraces>false</verbose-stacktraces>
<source-path append="true">
<path-element>E:\gitHub\easyAS-Worker\FD\src</path-element>
<path-element>C:\Program Files (x86)\FlashDevelop\Library\AS3\classes</path-element>
</source-path>
</compiler>
<file-specs>
<path-element>E:\gitHub\easyAS-Worker\FD\src\Main.as</path-element>
</file-specs>
<default-background-color>#FFFFFF</default-background-color>
<default-frame-rate>30</default-frame-rate>
<default-size>
<width>800</width>
<height>600</height>
</default-size>
</flex-config>
77 changes: 77 additions & 0 deletions FD/src/Main.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.system.WorkerState;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

import workers.Worker1;

// WorkerManager which will be taking care of all complicated stuff about AS Workers for you
import com.myflashlabs.utils.worker.WorkerManager;

/**
* ...
* @author Hadi Tavakoli - 1/29/2016 1:17 AM
*/
public class Main extends Sprite
{
private var _myWorker:WorkerManager;
private var _txt:TextField;

public function Main()
{
_txt = new TextField();
_txt.autoSize = TextFieldAutoSize.LEFT;
_txt.defaultTextFormat = new TextFormat(null, 40);
_txt.x = _txt.y = 50;
this.addChild(_txt);

// init the Manager and pass the class you want to use as your Worker
_myWorker = new WorkerManager(workers.Worker1, loaderInfo.bytes, this);

// listen to your worker state changes
_myWorker.addEventListener(Event.WORKER_STATE, onWorkerState);

// fire up the Worker
_myWorker.start();
}

private function onWorkerState(e:Event):void
{
trace("worker state = " + _myWorker.state)

// if the worker state is 'running', you can start communicating
if (_myWorker.state == WorkerState.RUNNING)
{
// create your own commands in your worker class, Worker1, i.e "forLoop" in this sample and pass in as many parameters as you wish
_myWorker.command("forLoop", onProgress, onResult, 10000);
}
}

/**
* this function can have as many parameters as you wish.
* this is just a contract between the worker class and this delegate.
* What you need to notice though, is that it must return void.
*/
private function onProgress($progress:Number):void
{
_txt.text = "$progress = " + $progress;
}

/**
* this function can have as many parameters as you wish.
* this is just a contract between the worker class and this delegate.
* What you need to notice though, is that it must return void.
*/
private function onResult($result:Number):void
{
_txt.text = "$result = " + $result;

// terminate the worker when you're done with it.
_myWorker.terminate();
}
}
}
Loading

0 comments on commit 96f069a

Please sign in to comment.