Posted By

arpo on 12/01/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

davidino1978


Loader


 / Published in: ActionScript 3
 

Loader code How to access the loaded clip.

  1. package com{
  2.  
  3. import flash.display.MovieClip;
  4. import flash.display.LoaderInfo;
  5. import flash.events.*;
  6. import flash.net.URLRequest;
  7. import flash.display.Loader;
  8.  
  9. public class Host extends MovieClip
  10. {
  11.  
  12. private var request:URLRequest;
  13. private var cont:Loader;
  14. private var loadedClip:MovieClip;
  15.  
  16. public function Host():void
  17. {
  18. request = new URLRequest("start.swf");
  19. cont = new Loader();
  20. cont.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
  21. cont.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
  22. cont.contentLoaderInfo.addEventListener(Event.INIT, onInit);
  23. cont.visible = false;
  24.  
  25. try {
  26. cont.load(request);
  27. }catch (error:SecurityError){
  28. trace(error);
  29. }
  30.  
  31. addChild(cont);
  32. }
  33.  
  34. private function onInit(event:Event):void
  35. {
  36. if (event.target is LoaderInfo){
  37. loadedClip = event.target.content as MovieClip;
  38. trace(loadedClip);
  39. }
  40. }
  41.  
  42. private function loadComplete(event:Event):void
  43. {
  44. cont.visible = true;
  45. loadedClip.addEventListener("someEvent", function(){
  46. trace("someEvent fired");
  47. });
  48. }
  49.  
  50. private function loadProgress(event:ProgressEvent):void
  51. {
  52. var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
  53. var progress:int=Math.round(percentLoaded * 100);
  54. }
  55. }
  56. }

Report this snippet  

You need to login to post a comment.