2 Replies Latest reply on Sep 22, 2010 12:40 AM by christoferek

    loadBytes differs in FLEX and AIR

    christoferek Level 1

      Hi All,

       

      I have some code that makes a "beep" sound. It work correctly in browser window but it doesn't in AIR appication.

      I found it here: http://www.actionscript.org/forums/showpost.php3?p=968797&postcount=25

       

      The problem is that the sound is really loaded but the Event.COMPLETE doesn't fire. So I can't hear the sound.

       

      Can you help with my problem?

       

              import flash.system.LoaderContext;


              function started(){
                  trace("in started");
                  var loadData:String="4357530a710d0000789cb556095413491aaece09e1bec2216844d60327492710810c7225 047041944bd401d3248d449274e804019705f1368e0aae8ab28e322e3a8a335e83283a3ef0168f1504749fccba 8a8a0a2e3ae88ea838bddde0391e3bebbeadd7799dfaebfbbeaafffbeb55573e60ce00c0ae1280a110903bb801 008a9d184c00827175a63441aee0e5ebb47aa394ec8df7ce32990c52a1302f2f4f90e727c0f099425150509010 160bc5623e89e01b0bf426249faf378ef00ee10d28c851a30ad7184c1a4ccfa3fa4806966b1aefedfd42365f67 7825ab370a103596810a54984e988f188422012ca47448905486a38809c393304c1b124ea1780a2d62cce2c912 fd7993702c13351ac929106db0f0d7e837f8a89cfc85886111cc87c57c383009f693fa074a2592b1b0480ac36f 70079183d438d484a81113f20ed95f4af2457e6f92dfc2bea0636a4d66c16f22bf46f28285bf72efb7f9a956bd b2d3908b6b076aa45609512daa43f5262369a968c052b54a9a89e13ac41482180c5a8d0aa10485f97c6316a6ca ce4366a3fc4ccade60e16be0a72e89cc2c2eeee345d6e9842fd14653029af971b431a9c0800a135023968bab50 123ee2c526898b93c6e88d2644af4263e4216440a0d1a8a511f27170241c314e2217f9cb15225144a09f2c3050 14a1f097f9c38112f980f76f535faac931552ee5db0b35f57fa1f606f5a55a3cae99a921b7e87b54fd44811112 4960a444f671d5f748bc5a2b8a6b66a36a058ee906aa604070234a3935defba555944d03fe4a35efdaf49f97f0 0ef5a59afa53127a87fa520dfb5f6cfaa004ef55615efbf4fe2d2d7c71f085f0808c461044bd8b157928422051 85ea519e0800b9d54832504fbfcca4c2be615e640f100fc31a80b3934321649e04f58aa61fa9b4cdaf9dd971c4 627fdf629fd0fe4d014460aab313f336d1a17c6eebbf61134188b3d7698e1d9d4110fd85aef3eca78c1ac6a94c e79c32579111a2a361b76262ec04fef2463bc1f19b1d2e8fdcfa242504974dac221e463470b82d8ea990390b42 3b127fba76a778ed30ffa1c39e04978ff158514c9cb4befef5e8ccc43104d1b974d52d79658d67971739db135f 18f9dc6d3e4f6eed6e10d0fb1e7ade8822e7b9ef589295f83bf6f016dc3da72cbad9baadeae4b23bf5c9fb769d e25009719ccf1cad82d6ad0351484175c7b452456c18574ebf1a2f6eadbf54d5727987a6cc1cffecaeefc155c4 f36fefadfffa8fc59789d45b6b5bef659414ee9c9892ea3eb3fff88ec64bbffc582a89997db6e7c23ffb6f54db 0346e4a12982fa96e093f5a3ab474e5d4425e4e0d675d44c6f0f84ce2cf2fbe1fbb927e6976c2b1f59a398b36c 6aee5fd3fed6ee513da908db517bc458937d686f454f79db5851bc646c76defed0eddb3aebb658d29a3ca5a7c4 d3890d37767a9b57063c1d7de7bad857174ac85667c5aec99f4b3fc13fa4a41fa312b27476f7dd1aa263187c32 bf98532b11d37ddcb8fac4b18b38f403f7526e3ea97bf4f4f9c1a000e2aab3e2e69c11d2da07b7adeb765bfe6b 397dcf4eee5cb7e42e569a803d217dadd9ec9271e98adbe6e25e5fab59b7034fea0ee434566c77d75ff388813b 9454424e8edb7ae782a226c382c41b15624367e5f5a96bb0198befdbb5e109f1b48a9aa4a413ed95b4f32bc3cf 193d1bc44d5088bc5769ecee5cfcdd6731cd538a7ed6261b73fb8c3645eea9bbbb169e6edeb86001cccb412f4c 78dcd37a3c43147d6fc952af13c92a2a211f97466e29941a06a5dffa86905f38101e1e76cd031c10b2aef7d5dd 7e7679c5a33f3c1b1b4decd960cfb30e097aac22885d849d9ddd30e21a80baab012d0ceaafa7c9be9c7ff3c79e 6153ea1636b92d31952594966e2e59ce19b3d4bd61ef83c02ad94a2aa151433d365625afaf04ac79c756f37d3c 634e829e1b2dd28d55f6893e17d073822d9e4ddb4aa4d2d65957baa3ba12d69a7d635abb8a77ced39e9d26ceaa 10c9d7479fc61764287c4abf29fe2aeaf7eddfed7330ad4a39b86a46c1fee7c92900887c6ae70e69bf3cb0e59c b2e66c0dbd721aecc23c0e7413dda129c36fd95aad0eb808c9ff74f769fd997478c4fa79ddb28646dfd1092d47 2a161f467b2d0226575ad4c99e452fb0af8c9967b8e2e8ea9a338e9fdfb22d21d41ed0383dc45c46fa22c9170e 8538549a7035fc214625e4eaace154a72b1886e9b58f7f8057f8d7f4a62cf322ba9b9b73b1a6f68b77bd22bfd5 5d54dc76543cb05ac8643be69499697f461c6e9d9fe66ffb139234a64f147e78535a3fb0a97fe01c51f173fdb3 abc5d7d37ed96fafccaefac711e466e2942db9955bcd2c2aa1e14ecdb3d6af995a0982462f72643c8d7b7ebe7c 6b79caeda992ed6b66c5ef2dddb769361a527deeef29cb6ae46d415dd9ab27b7369e9be3fb3479c8b1867bfbbe 2a449e14e510c2232bcb5d03fa38e1ee004c1c335c6fbbb8e42ff6333c65ab3e9fd8cb9bec3f954ae8b3a1e622 35b4ae122adbdb76c7357af7fd519d23e5a9cb0a970cd91c1e67b66913473d89ad4ee56f8d758c6cdcc1e76e3e 4b947576d20f7bf7ae383cf17bc7b1a3bfdc5eb6f7620c41ec319f5b7a6c8a7f7650cf2f2e9c1b78756c785ca4 9f20c8af9a6a54423600d0a3a10600aaff7f2d293c6aa656adcd35810fb449b919e4ad8527c7748846ff21d027 37eb7a672f1a75b893cd1e08a8970b6044a0a8c16ae05a24d0a16a0dc24cc472f56a1b2d86a851b5312f730639 661d47ae2749a343b51a3d6a3308566b8c062d52601987cdd6a032adc6e0f11645fa26859589233a54c43452d2 cc701c470a58f119b35095c97a500c9d4ddde3ec22a9979c14464caa2c14b745d4e4178d64260e7cc86ce48353 0e321d62f42614475426f2bb3718e1be352ec3c84b3b3937ce4a34e01a136ac985b874371a97c965bb59ba32b9 b63408b2674334368dc166b0d84c0b369bc386acd890b5250d6243366c0b3b3609603ab0998e6ca6139be9ccfe a8bb3488664127cda5332c588049634280c10280e2d0018d9c8b01000ba23320880d2088c9a237c151642d2088 c56635c14d3180ec5130a66b139c66a1b484951c5849239f54e0e5e5950591c37408b2e40cf218348863c52179 4a2805ca629111269d8cd80f28a559f980a64c66bc158d8cb3484dcb514d300a5e685ac34a1b58690b2bed6025 837c5221afc1964527e1a14ed42d8046e641ed0bf2ef5b4515bc595410460eff1b70cee0df";
                 
                  var bytes:ByteArray = new ByteArray();
                 
                  var data1:Array = loadData.split("");
                  var data2:Array = [];
                  for (var i:int = 0; i<data1.length; i += 2){
                      data2.push("0x"+data1 [i]+data1[i+1]);
                  }
                  for (var j:int = 0; j<data2.length; j++){
                      bytes[j] = data2[j];
                  }
                
                  var ldr:Loader = new Loader ();
                  var loaderContext:LoaderContext = new LoaderContext();
                  loaderContext.allowLoadBytesCodeExecution = true;
                  ldr.contentLoaderInfo.addEventListener (Event.COMPLETE, completeHandler);
                  ldr.loadBytes (bytes, loaderContext);
              } // function
             
              function completeHandler(e:Event):void {
                  var s:Sound = new e.currentTarget.content.sound[0]();
                  s.play();
                  trace("in complete handler");
              }