Making hotspots with Actionscript 3

Q&A about the latest versions
Post Reply
mikef
Posts: 11
Joined: Mon Jun 16, 2008 8:51 pm

I'm trying to build a container that can load a couple flash 9 panos linked with hotspots using Actionscript 3.0. the problem I'm having is that I can only get 1 hotspot to work. I have tried to use a similar structure to the park demo linked to on the API page, but converting it to AS3 has caused me some trouble.

My code is as follows:

Code: Select all

import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;

var loader:Loader;
loader = new Loader();
var id:Number = 1;
var url:String = "1.swf";
var urlReq:URLRequest = new URLRequest(url);
var vr:MovieClip;

function finished_loading (e:Event) {}
function initHandler(event:Event):void {
  trace("initHandler: " + event);
  vr = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip'
  vr.pano.setWindowSize(640,480);
  vr.pano.setWindowPos(1,1);
  
}
var hsZorder:Number = 1;
var HSmc:MovieClip = new HSdot;
function addNextPanoHotspot(HSid:String,HSpan:Number,HStilt:Number,HStext:String,HStargetid:Number) {
	hsZorder++;
 	
	vr.pano.addHotspot(HSid, HSpan, HStilt, HSmc);
	this.setChildIndex (HSmc, hsZorder);	
	}
	
//add the listener to get hotspot.x and hotspot.y from pano
addEventListener(Event.ADDED,myListener); 
function myListener(event:Event) {

setupHotspots ();
 
  }

 function setupHotspots() {
	// reset the hotspot Z order
	hsZorder = 0;
	// add the hotspots to the other panorama
addNextPanoHotspot("test1", 0, 25, "test1",1);	
addNextPanoHotspot("test2", 0, 0, "test2",2);
addNextPanoHotspot("test3", 0, -25, "test3",3);
	
} 
// Tell the loader to call 'finished_loading' after the swf is loaded.
loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, finished_loading);
loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
loader.load(urlReq);
addChild(loader); // add your swf directly to the stage

As far as I can tell the problem comes from the function addNextPanoHotspot. I think it is something to do with the z-order of the hotspots. The code above will only show the first hotspot, but If I remove the this.setChildIndex (HSmc, hsZorder); line, then I can only see the last hotspot.

Any ideas how to make all 3 hotspots show up?
Post Reply