|
3 | 3 | import contents.alert.Alert; |
4 | 4 |
|
5 | 5 | import flash.events.Event; |
| 6 | + import flash.events.IOErrorEvent; |
6 | 7 | import flash.filesystem.File; |
| 8 | + import flash.filesystem.FileMode; |
| 9 | + import flash.filesystem.FileStream; |
7 | 10 | import flash.system.Capabilities; |
8 | 11 | import flash.system.MessageChannel; |
9 | 12 | import flash.system.Worker; |
|
36 | 39 |
|
37 | 40 | private static var activated:Boolean = false ; |
38 | 41 |
|
| 42 | + |
39 | 43 | public static function setUp(TotalWorkers:uint = 4):void |
40 | 44 | { |
41 | 45 | activated = true ; |
42 | 46 | totalWorkers = TotalWorkers ; |
43 | 47 |
|
44 | | - var workerTarget:File = File.applicationDirectory.resolvePath("Data/bgWork.swf");//new File("D://Sepehr//gitHub/sepehrEngine/SaffronEngine/Data-sample/bgWork.swf") ; |
| 48 | + var workerTarget:File = File.applicationDirectory.resolvePath("Data/bgWork2.swf");//new File("D://Sepehr//gitHub/sepehrEngine/SaffronEngine/Data-sample/bgWork.swf") ; |
45 | 49 | if(!workerTarget.exists) |
46 | 50 | { |
47 | 51 | var moreHints:String = ''; |
48 | 52 | if(File.applicationDirectory.resolvePath("Data/bgWork").exists) |
49 | | - moreHints += " and remove the Data/bgWork now. "; |
50 | | - Alert.show("Add the bgWork file from Data-sample folder on Saffron to your Data folder"+moreHints) ; |
| 53 | + moreHints += " and remove the Data/bgWork now.\n"; |
| 54 | + if(File.applicationDirectory.resolvePath("Data/bgWork.swf").exists) |
| 55 | + moreHints += " and remove the Data/bgWork.swf now.\n"; |
| 56 | + Alert.show("Add the "+workerTarget.name+" file from Data-sample folder on Saffron to your Data folder"+moreHints) ; |
51 | 57 | } |
52 | 58 | var workerBytes:ByteArray = FileManager.loadFile(workerTarget); |
53 | 59 |
|
|
134 | 140 | } |
135 | 141 | } |
136 | 142 |
|
| 143 | + /**You will receive your byte array on the first unit of receiver array. so receiver must take an array*/ |
| 144 | + public static function base64ToByte(base64String:String,receiver:Function):void |
| 145 | + { |
| 146 | + var currentId:uint = lastID++ ; |
| 147 | + |
| 148 | + funcList.push(receiver); |
| 149 | + idList.push(currentId); |
| 150 | + |
| 151 | + var tempFile:File = File.createTempFile() ; |
| 152 | + var fileStream:FileStream = new FileStream(); |
| 153 | + fileStream.addEventListener(Event.CLOSE,fileSaved); |
| 154 | + fileStream.openAsync(tempFile,FileMode.WRITE); |
| 155 | + trace("** Save "+base64String.length+" to temp file targeted : "+tempFile.nativePath); |
| 156 | + fileStream.writeUTFBytes(base64String); |
| 157 | + fileStream.close(); |
| 158 | + |
| 159 | + function fileSaved(event:Event):void |
| 160 | + { |
| 161 | + trace("** File saved done!!"); |
| 162 | + fileStream.close(); |
| 163 | + var toSendValue:Array = [BgWorker.id_base64ToByte,currentId,tempFile.nativePath] ; |
| 164 | + |
| 165 | + if(activated) |
| 166 | + { |
| 167 | + selectSenderTosend().send(toSendValue); |
| 168 | + } |
| 169 | + else |
| 170 | + { |
| 171 | + setUpDebugOnce(); |
| 172 | + bgEmulator.handleCommandMessage(toSendValue); |
| 173 | + } |
| 174 | + } |
| 175 | + } |
137 | 176 |
|
138 | 177 | /**You will recevie your objec on your receiver function on the first unit of an Array.*/ |
139 | 178 | public static function JSONPars(str:String,receiver:Function):void |
|
173 | 212 | received = receiverChannel.receive(); |
174 | 213 | } |
175 | 214 | trace("Received data type is : "+getQualifiedClassName(received[1])); |
176 | | - callFunction(received[0],received[1]); |
| 215 | + var callerId:uint = received[0] ; |
| 216 | + |
| 217 | + |
| 218 | + callFunction(callerId,received[1]); |
177 | 219 | } |
178 | 220 |
|
179 | 221 | /**Send this data to its recever*/ |
|
0 commit comments