Posted By

two7s_clash on 10/11/14


Tagged


Versions (?)

Fixing Flash error 1046 against SoundEvent


 / Published in: ActionScript 3
 

see: http://stackoverflow.com/questions/26302428/fixing-flash-error-1046-against-soundevent

  1. package com.argosy.cengage.sherwood
  2. {
  3. import flash.display.Sprite;
  4. import flash.events.*;
  5.  
  6. public class Shell extends Sprite
  7. {
  8. import flash.display.BitmapData;
  9. import flash.geom.Matrix;
  10. import flash.display.DisplayObject;
  11. import flash.display.Loader;
  12. import flash.net.URLLoader;
  13. import flash.net.URLRequest;
  14. import flash.media.Sound;
  15. import flash.events.Event;
  16. import fl.video.SoundEvent;
  17. import flash.media.SoundTransform;
  18. import flash.system.ApplicationDomain;
  19. import flash.system.LoaderContext;
  20. import flash.media.SoundMixer;
  21. import flash.filters.DropShadowFilter;
  22.  
  23. import com.argosy.util.CustomLoader;
  24. import com.argosy.events.XMLEvent;
  25. import com.argosy.ui.ToggleButton;
  26. import com.argosy.ui.ToggleButtonGroup;
  27. import com.argosy.ui.CustomButton;
  28. import com.argosy.ui.ProgressBar;
  29. import com.cengage.events.SubmitEvent;
  30. import com.argosy.cengage.sherwood.Menu;
  31. import com.argosy.cengage.sherwood.VolumeControls;
  32.  
  33. // Display Objects
  34. private var frame:Sprite;
  35. private var frameBG:Sprite;
  36. private var dotFill:Sprite;
  37. private var UpRightLogo:Sprite;
  38. private var UpLeftLogo:Sprite;
  39. private var coverGraphic:Sprite;
  40. private var copyrt:Sprite;
  41. private var menu:Menu;
  42. private var container:Sprite;
  43. private var assetMask:Sprite;
  44. private var backBut:Sprite;
  45. private var nextBut:Sprite;
  46. private var backTopBut:Sprite;
  47. private var nextTopBut:Sprite;
  48. private var homeBut:Sprite;
  49. private var seeItToggle:ToggleButton;
  50. private var tryItToggle:ToggleButton;
  51. private var reviewItToggle:ToggleButton;
  52. private var toggleGrp:ToggleButtonGroup;
  53. private var xml_pb:ProgressBar;
  54. private var asset_pb:ProgressBar;
  55. private var volCtrls:VolumeControls;
  56.  
  57. // Properties
  58. private var w:Number;
  59. private var h:Number;
  60. private var toc:String;
  61. private var xLoader:URLLoader;
  62. private var xdata:XML;
  63. private var assetLoader:Loader;
  64. private var assetXML:XML;
  65. private var asset:*;
  66. private var dot:BitmapData;
  67.  
  68. // Constructor
  69. public function Shell() { init(); }
  70.  
  71. private function init():void
  72. {
  73. XML.prettyPrinting = false;
  74. XML.ignoreWhitespace = true;
  75.  
  76. w = 1000;
  77. h = 640;
  78.  
  79. frameBG = new SherwoodShellFrameBG();
  80. frameBG.cacheAsBitmap = true;
  81. this.addChild(frameBG);
  82.  
  83. var matrix:Matrix = new Matrix();
  84. dotFill = new Sprite();
  85. dot = new BitmapData(9, 9, true, 0x00000000);
  86. dot.draw(new BannerDot(), matrix);
  87. matrix.rotate(Math.PI / 4);
  88. dotFill.graphics.beginBitmapFill(dot, matrix, true, false);
  89. dotFill.graphics.drawRect(0, 0, w, 95);
  90. dotFill.graphics.endFill();
  91. addChild(dotFill);
  92.  
  93. UpRightLogo = new UpperRightLogo();
  94. this.addChild(UpRightLogo);
  95.  
  96. UpLeftLogo = new UpperLeftLogo();
  97. this.addChild(UpLeftLogo);
  98.  
  99. coverGraphic = new CoverGraphic();
  100. this.addChild(coverGraphic);
  101.  
  102. frame = new SherwoodShellFrame();
  103. frame.filters = [new DropShadowFilter(2, 90, 0, 0.75, 15, 15, 1, 1, false, false, false)];
  104. frame.cacheAsBitmap = true;
  105. this.addChild(frame);
  106.  
  107. container = new Container();
  108. this.addChild(container);
  109.  
  110. menu = new Menu();
  111. menu.width = 230;
  112. menu.height = container.height;
  113. menu.border = false;
  114. menu.backgroundAlpha = 0;
  115. menu.addEventListener(XMLEvent.SELECT, selectHandler);
  116. this.addChild(menu);
  117.  
  118. assetMask = new ContainerMask();
  119. assetMask.visible = false;
  120. this.addChild(assetMask);
  121.  
  122. //Home button
  123. homeBut = new CustomButton(new HomeBtn(), new HomeOver(), new HomeDown(), new HomeBtn());
  124. homeBut.addEventListener(MouseEvent.CLICK, homeHandler);
  125. this.addChild(homeBut);
  126.  
  127. seeItToggle = new ToggleButton(new SeeItUp(), new SeeItOver(), new SeeItDown(), new SeeItActiveUp(), new SeeItActiveOver(), new SeeItActiveDown());
  128. this.addChild(seeItToggle);
  129. seeItToggle.addEventListener(MouseEvent.CLICK, seeItToggleHandler);
  130.  
  131. tryItToggle = new ToggleButton(new TryItUp(), new TryItOver(), new TryItDown(), new TryItActiveUp(), new TryItActiveOver(), new TryItActiveDown());
  132. this.addChild(tryItToggle);
  133. tryItToggle.addEventListener(MouseEvent.CLICK, tryItToggleHandler);
  134.  
  135. reviewItToggle = new ToggleButton(new ReviewItUp(), new ReviewItOver(), new ReviewItDown(), new ReviewItActiveUp(), new ReviewItActiveOver(), new ReviewItActiveDown());
  136. this.addChild(reviewItToggle);
  137. reviewItToggle.addEventListener(MouseEvent.CLICK, reviewItToggleHandler);
  138.  
  139. toggleGrp = new ToggleButtonGroup();
  140. toggleGrp.addToggleButton(seeItToggle);
  141. toggleGrp.addToggleButton(tryItToggle);
  142. toggleGrp.addToggleButton(reviewItToggle);
  143.  
  144. // back and next buttons
  145. backBut = new CustomButton(new BackBtn(), new BackBtnOver(), new BackBtnDown(), new BackBtn());
  146. backBut.addEventListener(MouseEvent.CLICK, backHandler);
  147. this.addChild(backBut);
  148.  
  149. nextBut = new CustomButton(new NextBtn(), new NextBtnOver(), new NextBtnDown(), new NextBtn());
  150. nextBut.addEventListener(MouseEvent.CLICK, nextHandler);
  151. this.addChild(nextBut);
  152.  
  153. // TOP back and next buttons
  154. nextTopBut = new CustomButton(new NextTopBtn(), new NextTopOver(), new NextTopDown(), new NextTopBtn());
  155. nextTopBut.addEventListener(MouseEvent.CLICK, nextHandler);
  156. this.addChild(nextTopBut);
  157.  
  158. backTopBut = new CustomButton(new BackTopBtn(), new BackTopOver(), new BackTopDown(), new BackTopBtn());
  159. backTopBut.addEventListener(MouseEvent.CLICK, backHandler);
  160. this.addChild(backTopBut);
  161.  
  162. copyrt = new copyright();
  163. this.addChild(copyrt);
  164.  
  165. //volume controls
  166. volCtrls = new VolumeControls();
  167. volCtrls.addEventListener(SoundEvent.SOUND_UPDATE, volumeHandler);
  168. this.addChild(volCtrls);
  169.  
  170. // XML loading objects
  171. xLoader = new URLLoader();
  172. xLoader.addEventListener(IOErrorEvent.IO_ERROR, xLoaderIOError);
  173. xLoader.addEventListener(Event.COMPLETE, xLoaderComplete);
  174. xLoader.addEventListener(ProgressEvent.PROGRESS, xLoaderProgress);
  175. xml_pb = new ProgressBar();
  176. xml_pb.delay = 0.2;
  177. xml_pb.width = menu.width - 10;
  178. xml_pb.height = 10;
  179. xml_pb.value = 0;
  180. xml_pb.fillColor = 0x0099cc; //0x1dcb86; //0x07b2e6;
  181. xml_pb.addEventListener('fadeOutComplete', xmlPbFadeOutComplete);
  182. addChild(xml_pb);
  183.  
  184. // Asset loading objects
  185. assetLoader = new Loader();
  186. assetLoader.contentLoaderInfo.addEventListener(Event.OPEN, assetLoaderOpen);
  187. assetLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, assetLoaderIOError);
  188. assetLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, assetLoaderProgress);
  189. assetLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS , assetLoaderHTTPStatus);
  190. assetLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, assetLoaderComplete);
  191. assetLoader.contentLoaderInfo.addEventListener(Event.INIT, assetLoaderInit);
  192. assetLoader.contentLoaderInfo.addEventListener(Event.UNLOAD, assetLoaderUnload);
  193. asset_pb = new ProgressBar();
  194. asset_pb.delay = 0.25;
  195. asset_pb.width = Math.round(container.width / 2);
  196. asset_pb.height = 15;
  197. asset_pb.value = 0;
  198. asset_pb.fillColor = 0x0099cc; // burgundy //0x1dcb86 = teal green
  199. asset_pb.addEventListener('fadeOutComplete', assetPbFadeOutComplete);
  200. addChild(asset_pb);
  201.  
  202. // to other stuff
  203. if (stage) { layout(); }
  204. addEventListener(Event.ADDED_TO_STAGE, addedToStage);
  205. }
  206.  
  207. public override function get width():Number { return w; }
  208.  
  209. public override function set width(n:Number):void
  210. {
  211. w = n;
  212. layout();
  213. }
  214.  
  215. public override function get height():Number { return h; }
  216.  
  217. public override function set height(n:Number):void
  218. {
  219. h = n;
  220. layout();
  221. }
  222.  
  223. public function get data():XML { return menu.data; }
  224.  
  225. public function set data(xml:XML):void
  226. {
  227. menu.data = xml;
  228. }
  229.  
  230. public function get config():String { return toc; }
  231.  
  232. public function set config(url:String):void
  233. {
  234. toc = url;
  235. xdata = null;
  236.  
  237. xml_pb.value = 0;
  238. xml_pb.fadeIn();
  239. xml_pb.visible = true;
  240.  
  241. try { xLoader.load(new URLRequest(toc)); }
  242. catch (err:SecurityError)
  243. {
  244. dispatchEvent(new TextEvent('error', false, false, ':: Shell :: set config ::\nA security error has occurred. (' + err.message + ')'));
  245. trace('A security error has occurred.');
  246. }
  247. catch (err:Error)
  248. {
  249. dispatchEvent(new TextEvent('error', false, false, ':: Shell :: set config ::\nAn error has occurred. (' + err.message + ')'));
  250. trace('An error has occurred.');
  251. }
  252. }
  253.  
  254. public function get state():String { return menu.state; }
  255.  
  256. public function set state(s:String):void { menu.state = s; }
  257.  
  258. private function layout():void
  259. {
  260. // Set sizes
  261. frameBG.width = w;
  262. frameBG.height = h;
  263. frame.width = w - 30;
  264. frame.height = h - 55;
  265.  
  266. // Position main elements
  267. frame.x = 10;
  268. frame.y = 40;
  269. container.x = 250;
  270. container.y = 70;
  271. assetMask.x = container.x;
  272. assetMask.y = container.y;
  273. menu.x = frame.x + 1;
  274. menu.y = 70;
  275.  
  276. // Position banner elements
  277. UpRightLogo.x = w - UpRightLogo.width - 20;
  278. UpRightLogo.y = -4;
  279. UpLeftLogo.x = 130;
  280. UpLeftLogo.y = 5;
  281. coverGraphic.x = 0;
  282. coverGraphic.y = 0;
  283.  
  284. // Position banner buttons
  285. homeBut.x = frame.x + 8;
  286. homeBut.y = frame.y;
  287. seeItToggle.x = homeBut.x + homeBut.width;
  288. seeItToggle.y = frame.y;
  289. tryItToggle.x = seeItToggle.x + seeItToggle.width;
  290. tryItToggle.y = frame.y;
  291. reviewItToggle.x = tryItToggle.x + tryItToggle.width;
  292. reviewItToggle.y = frame.y;
  293. nextTopBut.x = Math.round(frame.x + frame.width - nextTopBut.width - 8);
  294. nextTopBut.y = frame.y;
  295. backTopBut.x = Math.round(nextTopBut.x - backTopBut.width);
  296. backTopBut.y = frame.y;
  297. volCtrls.x = Math.round(backTopBut.x - volCtrls.width);
  298. volCtrls.y = frame.y; //Math.round(frame.y + volCtrls.height / 2);
  299.  
  300. // Position secondary nav buttons and copyright
  301. nextBut.x = Math.round(container.x + container.width - nextBut.width - 5);
  302. nextBut.y = Math.round(container.y + container.height);
  303. backBut.x = Math.round(nextBut.x - backBut.width - 5);
  304. backBut.y = nextBut.y;
  305. copyrt.x = frame.x;
  306. copyrt.y = frame.y + frame.height;
  307. nextBut.visible = false;
  308. backBut.visible = false;
  309.  
  310. // Position load bars
  311. xml_pb.x = menu.x + 5;
  312. xml_pb.y = menu.y + 5;
  313. asset_pb.x = Math.round(container.x + (container.width - asset_pb.width) / 2);
  314. asset_pb.y = Math.round(container.y + (container.height - asset_pb.height) / 2);
  315. }
  316.  
  317. private function addedToStage(evt:Event):void { layout(); }
  318.  
  319. private function seeItToggleHandler(evt:MouseEvent):void { menu.limitType = (menu.limitType != 'see') ? 'see' : ''; }
  320.  
  321. private function tryItToggleHandler(evt:MouseEvent):void { menu.limitType = (menu.limitType != 'try') ? 'try' : ''; }
  322.  
  323. private function reviewItToggleHandler(evt:MouseEvent):void { menu.limitType = (menu.limitType != 'review') ? 'review' : ''; }
  324.  
  325. private function selectHandler(evt:XMLEvent):void
  326. {
  327. if (evt.xml == null) { return; }
  328. trace('Selected "' + evt.xml.label[0].children().toXMLString() + '". Load "' + evt.xml.@src[0].toString() + '".');
  329.  
  330. var type:String = evt.xml.@type[0];
  331. if (type != menu.limitType)
  332. {
  333. menu.limitType = '';
  334. toggleGrp.untoggle();
  335. }
  336.  
  337. loadAsset(evt.xml);
  338. }
  339.  
  340. private function loadAsset(xml:XML):void
  341. {
  342. // Fail-safes
  343. if (xml == null) { return; }
  344. else if (xml.@src[0] == null) { return; }
  345.  
  346. // Remove the old asset, if applicable
  347. try { assetLoader.close(); }
  348. catch (err:Error) { /* no stream to close; ignore. */ }
  349. if (asset != null) { unloadAsset(); }
  350.  
  351. assetXML = xml;
  352. var src:String = xml.@src[0].toString();
  353.  
  354. // Load new asset
  355. var context:LoaderContext = new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain));
  356. assetLoader.load(new URLRequest(src), context);
  357. }
  358.  
  359. private function unloadAsset():void
  360. {
  361. if (container.contains(assetLoader)) { container.removeChild(assetLoader); }
  362. assetLoader.mask = null;
  363. asset.removeEventListener(SubmitEvent.SUBMIT, submitHandler);
  364. asset = null;
  365. assetLoader.unload();
  366. assetXML = new XML();
  367. }
  368.  
  369. private function backHandler(evt:MouseEvent):void { menu.back(); }
  370.  
  371. private function nextHandler(evt:MouseEvent):void { menu.next(); }
  372.  
  373. private function homeHandler(evt:MouseEvent):void { menu.selectFirstAsset(); }
  374.  
  375. private function volumeHandler(evt:SoundEvent):void { this.soundTransform = evt.soundTransform; }
  376.  
  377. private function xLoaderIOError(evt:IOErrorEvent):void
  378. {
  379. xdata = null;
  380. xml_pb.fadeOut();
  381. dispatchEvent(new TextEvent('error', false, false, ':: Shell :: xLoaderIOError ::\nFailed to load XML. (' + evt.text + ')'));
  382. trace('\n:: App :: xLoaderIOError :: Failed to load XML. (' + evt.text + ')');
  383. }
  384.  
  385. private function xLoaderProgress(evt:ProgressEvent):void { xml_pb.value = evt.bytesLoaded / evt.bytesTotal; }
  386.  
  387. private function xLoaderComplete(evt:Event):void
  388. {
  389. try { xdata = new XML(evt.target.data); }
  390. catch(err:Error)
  391. {
  392. dispatchEvent(new TextEvent('error', false, false, ':: Shell :: xLoaderComplete ::\nFailed to parse XML. (' + err + ')'));
  393. return;
  394. }
  395. xml_pb.fadeOut();
  396. }
  397.  
  398. private function xmlPbFadeOutComplete(evt:Event):void
  399. {
  400. // The load was successful if xdata is defined
  401. if (xdata != null)
  402. {
  403. this.data = xdata;
  404. dispatchEvent(new Event('ready'));
  405. homeHandler(new MouseEvent(MouseEvent.CLICK));
  406. }
  407. }
  408.  
  409. private function assetLoaderOpen(evt:Event):void
  410. {
  411. //dispatchEvent(new TextEvent('debug', false, false, 'Asset opened. Download commencing.'));
  412. asset_pb.fadeIn();
  413. }
  414.  
  415. private function assetLoaderIOError(evt:IOErrorEvent):void
  416. {
  417. asset_pb.fadeOut();
  418. dispatchEvent(new TextEvent('debug', false, false, 'Could not locate asset.'));
  419. dispatchEvent(new TextEvent('error', false, false, ':: Shell :: assetLoaderIOError ::\nFailed to load asset. (' + evt.text + ')'));
  420. //trace('\n:: App :: xLoaderIOError :: Failed to load asset. (' + evt.text + ')');
  421. }
  422.  
  423. private function assetLoaderHTTPStatus(evt:HTTPStatusEvent):void
  424. {
  425. //dispatchEvent(new TextEvent('debug', false, false, 'Asset HTTP status = ' + evt.status + '.'));
  426. }
  427.  
  428. private function assetLoaderProgress(evt:ProgressEvent):void
  429. {
  430. asset_pb.value = evt.bytesLoaded / evt.bytesTotal;
  431. //dispatchEvent(new TextEvent('debug', false, false, 'Asset downloading... ' + Math.round(asset_pb.value * 100) + '% complete.'));
  432. }
  433.  
  434. private function assetLoaderComplete(evt:Event):void
  435. {
  436. //dispatchEvent(new TextEvent('debug', false, false, 'Asset download complete.'));
  437. asset = assetLoader.content;
  438. asset.addEventListener(SubmitEvent.SUBMIT, submitHandler);
  439. asset_pb.fadeOut();
  440. }
  441.  
  442. private function assetLoaderInit(evt:Event):void
  443. {
  444. //dispatchEvent(new TextEvent('debug', false, false, 'Asset initialized. Ready for interaction!'));
  445. }
  446.  
  447. private function assetLoaderUnload(evt:Event):void
  448. {
  449. //dispatchEvent(new TextEvent('debug', false, false, 'Asset unloaded. Stopping all sounds.'));
  450. SoundMixer.stopAll();
  451. }
  452.  
  453. private function assetPbFadeOutComplete(evt:Event):void
  454. {
  455. // The load was successful if asset is defined.
  456. if (asset != null)
  457. {
  458. assetLoader.x = Math.max(0, Math.round(container.width - asset.width) / 2);
  459. assetLoader.y = Math.max(0, Math.round(container.height - asset.height) / 2);
  460. container.addChild(assetLoader);
  461. assetLoader.mask = assetMask;
  462. if (assetXML != null && assetXML.attribute('src')[0] != null
  463. && (assetXML.attribute('type')[0] == 'see' || assetXML.attribute('type')[0] == 'info'))
  464. { submitHandler(null); }
  465. }
  466. }
  467.  
  468. private function submitHandler(evt:SubmitEvent):void
  469. {
  470. menu.setItemComplete();
  471. dispatchEvent(new TextEvent('submit', false, false, this.state));
  472.  
  473. if (assetXML != null)
  474. {
  475. var type:String = assetXML.attribute('type')[0];
  476. if (type == 'try' || type == 'review') { dispatchEvent(new TextEvent('alert', false, false, 'Your responses have been submitted.')); }
  477. }
  478. }
  479. }
  480. }

Report this snippet  

You need to login to post a comment.