0

I'm making a book/magazine with EZFLAR and Flash, but I was going to need a lot of markers (and they become indistinguishable by FLARToolkit the more they are), so now I'm trying a different approach: just three markers and then, load a different SWF that triggers different actions for each marker.

To do so, I made a loader.swf that will be in charge of loading any of the specific swf depending on what the user clicks. I started with my first button and it loads fine, just it has two problems.

First problem, and not so important, is that I can't seem to add anything over the webcam stream, not even placing it on the EZLFAR.fla, the webcam always covers everything. I decided, then, to add a little margin where I can place a UI (maybe a back button or the other swf loaders).

Second problem happened, I can't get either unload() nor unloadAndStop() working. I've put a trace inside the function to see if it enters on click, and it does, but it just doesn't unload the webcam swf. Also, if I add the listener to the webcam swf it doesn't detect clicks on it.

This is my code:

import flash.display.Loader
import flash.net.URLRequest
import flash.events.Event

var myLoader:Loader = new Loader(); 

rptr.addEventListener (MouseEvent.CLICK, raptorLoad);

function raptorLoad (e:MouseEvent):void 
{
    var url:URLRequest = new URLRequest("rptr.swf"); 
    myLoader.load(url); 
    addChild(myLoader);
}

myLoader.addEventListener(MouseEvent.CLICK, unLoad);

function unLoad (event:MouseEvent):void 
{
    trace("click!");
    myLoader.unloadAndStop();
}

Any help is greatly appreciated, thanks!

Kirby
  • 455
  • 6
  • 23

1 Answers1

1

Loader.unload() doesn't destroy the loaded content, it just removes it from the Loader instance's display list. You'll need to destroy the content manually. Check out the Loader.unload documentation for more info.

Your other issue of loading content above the camera...without seeing more of that code, it's hard to tell what the issue might be. I would suggest maybe adding an event listener to your loader. Wait until the load is complete before adding it.

Corey
  • 5,818
  • 2
  • 24
  • 37
  • I didn't mean loading something above the stream. I mean, for example, text I place on the canvas gets covered by the camera stream, how can I manage the layers in that case? Also, isn't unloadAndStop supposed to get rid of everything? – Kirby May 02 '11 at 20:58
  • unloadAndStop attempts to remove references within the loaded swf and make the content available for garbage collection. When you call this, do you get any errors or does it just act like it's not working? The layering issue could be solved by just using setChildIndex...assuming they're all in the same display list. – Corey May 02 '11 at 21:18
  • No errors, just nothing happens. Like if I didn't click on the loaded swf. – Kirby May 02 '11 at 21:48
  • Also, I tried this: myLoader.x = 200; before addChild() and it didn't work, myLoader loads at 0,0 – Kirby May 02 '11 at 21:53