trapping hotspots in Flash

Q&A about the latest versions
Post Reply
bizmillah
Posts: 12
Joined: Fri Sep 07, 2007 5:16 pm

Fri Sep 07, 2007 5:28 pm

Hi,

I am testing Pano2VR and would like to know how can I trap hotspots from a calling flash AS2 document. This is what I do:

I am running an actionscript application, which loads a pano generated by Pano2VR as a Flash8 SWF, in a movieclip container. This works fine, but then I need to know in the parent application, when the used clicks on a hotspot, because in this case I don't want to load a URL, but instead I need to take some other action, internal to the parent.

Is there a listener I can use?

Any hints? or any doc I should read to find the answer?

thanx
Silvano
User avatar
thomas
Chief Gnome
Posts: 2564
Joined: Fri Sep 01, 2006 3:56 pm
Location: Vienna, Austria
Contact:

Sat Sep 08, 2007 12:47 am

You can set a function "onClickQtHotspot" that gets the following parameters: id(=Hotspot number), title, url, target. Something like

Code: Select all

<movieclip>.pano.onClickQtHotspot=function(id,title,url,target)  {
// do something
}
should do the trick.
MfG, Thomas
bizmillah
Posts: 12
Joined: Fri Sep 07, 2007 5:16 pm

Mon Sep 10, 2007 8:29 am

Thanx! actually, where do I find info on all the stuff I can do? I mean, where is the <movieclip>.pano.xxxx defined?

cheers
Silvano
User avatar
thomas
Chief Gnome
Posts: 2564
Joined: Fri Sep 01, 2006 3:56 pm
Location: Vienna, Austria
Contact:

Mon Sep 10, 2007 8:15 pm

Currently only in my source code and on this forum.... but I am preparing a document with all the collected wisdom.
MfG, Thomas
bizmillah
Posts: 12
Joined: Fri Sep 07, 2007 5:16 pm

Mon Sep 10, 2007 11:49 pm

Thomas,

thanx again, well if you're the developer, then you will probably receive the email I just sent to support on this. I am really stuck on a rather project with a deadline. All I need is a method/handler to get out of a pano with info on a hotspot click. I tried the one you gave me but it doesn't seem to work. Perhaps I need a little more detailed example...

cheers
Silvano
User avatar
thomas
Chief Gnome
Posts: 2564
Joined: Fri Sep 01, 2006 3:56 pm
Location: Vienna, Austria
Contact:

Fri Sep 14, 2007 11:13 pm

Today I had the chance to test it and it works for me as expected. Maybe I should have mentioned that you need to apply this handler after the panorama is initialized so the routine needs to be in the onInit event handler. Here is my code:

Code: Select all

var vr:MovieClip = _root.createEmptyMovieClip("vr", 1);
vr._lockroot=true;

var myLoader = new MovieClipLoader();
var myListener = new Object();

myListener.onLoadInit = function () {
// callback after the pano is fully loaded	
  vr.pano.onClickQtHotspot=function(id:Number,title:String,url:String,target:String)     
  {
    // add your code here!
    trace(id + "," + title);
  }
};
myLoader.addListener(myListener);
myLoader.loadClip("mypanorama.swf", vr);
MfG, Thomas
bizmillah
Posts: 12
Joined: Fri Sep 07, 2007 5:16 pm

Mon Sep 17, 2007 5:01 pm

Thomas,

thanx a million, it works!
what I did not know is that I had to stick the function in the onLoadInit listener.

cheers
Silvano
bizmillah
Posts: 12
Joined: Fri Sep 07, 2007 5:16 pm

Wed Sep 19, 2007 7:58 pm

Thomas,

the bas news is that I am now porting my app to AS3, mainly for performance reasons. So what's the equivalent for AS3?

cheers
Sil
User avatar
thomas
Chief Gnome
Posts: 2564
Joined: Fri Sep 01, 2006 3:56 pm
Location: Vienna, Austria
Contact:

Sun Sep 23, 2007 12:13 am

The code is a bit more complicated because you need to cast the loaded object to a movie clip but most of the properties (if already implemented, e.g. point hotspots as in the tour demo are currently missing) work the same as with AS2. Here is a sample code for AS3:

Code: Select all

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

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

// This is done after the swf is loaded.
function finished_loading (e:Event) {
  vr.pano.onClickQtHotspot=function(id:Number,title:String,url:String,target:String)     
  {
    // add your code here!
    trace(id + "," + title);
  } 
}
function initHandler(event:Event):void {
    trace("initHandler: " + event);
	vr = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip'
//	vr.pano.setWindowSize(200,100);
}


// 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
MfG, Thomas
bizmillah
Posts: 12
Joined: Fri Sep 07, 2007 5:16 pm

Tue Oct 02, 2007 9:42 pm

Thomas,

thanx for the code and sorry for the late post. Just got to test your code, but had no luck. I restructured it as a class, and just instanced it in the document class of an empty fla. The pano loads, but I get a lot of scary runtime errors:
  • initHandler: [Event type="init" bubbles=false cancelable=false eventPhase=2]
    TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@132eae61 to flash.display.MovieClip.
    at panorama/::initHandler()
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at panorama/::finished_loading()
    ReferenceError: Error #1056: Cannot create property panomask on panorama.

    ReferenceError: Error #1056: Cannot create property prebar on panorama.

    ReferenceError: Error #1056: Cannot create property pretxt on panorama.
Here's the code:

Code: Select all

package {
	import flash.display.*; 
	import flash.net.URLRequest; 
	import flash.events.Event; 
	
	public class panorama extends MovieClip {
		
		
		var loader:Loader = new Loader(); 
		var url:String = "CLIPS/PANOS/VP_B4S2.swf"; 
		var urlReq:URLRequest = new URLRequest(url); 
		var vr:MovieClip; 
		
		public function panorama() {
			// 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 
		}

		// This is done after the swf is loaded. 
		function finished_loading (e:Event) { 
		  vr.pano.onClickQtHotspot=function(id:Number,title:String,url:String,target:String)  { 
	    	// add your code here! 
	   		 trace(id + "," + title); 
  			} 
		} 
		
		function initHandler(event:Event):void { 
   			trace("initHandler: " + event); 
   			vr = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip' 
			//   vr.pano.setWindowSize(200,100); 
		} 
	}
}


User avatar
thomas
Chief Gnome
Posts: 2564
Joined: Fri Sep 01, 2006 3:56 pm
Location: Vienna, Austria
Contact:

Tue Oct 09, 2007 6:11 pm

Hmm...... Did you export a Flash 8 or Flash 9 pano? I guess the pano is still AS2/AVM1/Flash 8 because otherwise I can not understand this error message.
MfG, Thomas
bizmillah
Posts: 12
Joined: Fri Sep 07, 2007 5:16 pm

Tue Oct 09, 2007 11:42 pm

Thomas,

you were right, I had mixed up folders and was running this code on a Flash8 version of the pano. However... this is what I get when I run my application of a Flash9 pano:

Code: Select all

-- loadPano - loading : ../CLIPS/PANOS/VP_B4S.swf
initHandler: [Event type="init" bubbles=false cancelable=false eventPhase=2]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/init_cube()
	at PanoCube/init()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
-- zoomOn called.  
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/doEnterFrame()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at PanoCube/setup_cube()
	at PanoCube/::init_cubefaces()
	at PanoCube/init_faces()
	at flash3dpano_empty_fla::MainTimeline/flash3dpano_empty_fla::frame10()
and here is my loadPano:

Code: Select all

package {
	import flash.display.*; 
	import flash.net.URLRequest; 
	import flash.events.Event; 
	
	import  flash.display.MovieClip;
	
	public class Panorama extends MovieClip {
		public var 	file: 	String;			// filename where pano is
		public var 	pan:	Number;			// pan positioning on open
		public var 	tilt:	Number;			// tilt positioning on open
		public var 	fov:	Number;			// field of view on open
		public var 	rot:	Number;			// rotation soon after open
		public var 	mc:		MovieClip;
		public var 	texto:	String;
		public var 	type:	String;			// XP or VP
		
		var loader:Loader = new Loader(); 
		var url:String; 
		var urlReq:URLRequest = new URLRequest(url); 
		var vr:MovieClip; 
		
		public function Panorama (infoObject:Object) {
			trace ("Panorama : "+infoObject.name);
			panoData (infoObject);
			loadPano();
		
		}
		
		private function panoData(infoObject:Object):void {
			
			if (infoObject.parameters != undefined) {
         		for (var paramName:String in infoObject.parameters)
             	{                    
			 	 	trace("--  > " + paramName + ": " + infoObject.parameters[paramName]);
				 	switch (paramName) {
					 	case "FILE" :
							file =  infoObject.parameters[paramName];
							urlReq.url = Vars.pathPano+file+".swf";
							break;
					 	case "PAN" :
							pan = infoObject.parameters[paramName];
							break;
					 	case "TILT" :
							tilt = infoObject.parameters[paramName];
							break;
					 	case "FOV" :
							fov = infoObject.parameters[paramName];
							break;
						case "ROT" :
							 rot = infoObject.parameters[paramName]; 
							break;		
						case "TEXT" :
							 texto = infoObject.parameters[paramName]; 
							break;	

                	}
            	}
	 		}
		}
		
		private function loadPano() {
			trace("-- loadPano - loading : "+urlReq.url);
 			// 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 

		// This is done after the swf is loaded. 
		function finished_loading (e:Event) { 
 			 vr.pano.onClickQtHotspot=function(id:Number,title:String,url:String,target:String) { 
    		 	// add your code here! 
    			trace("finished_loading pano: "+id + "," + title); 
  			 } 
		 } 
		
		function initHandler(event:Event):void { 
   			trace("initHandler: " + event); 
   			vr = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip' 
			//   vr.pano.setWindowSize(200,100); 
		} 

		}

	}
}
The Panorama class is instanced by an FLVPlayback class that runs into a cuePoint, which holds the name and parameters of the the pano to load. Here's how it's instanced:

Code: Select all

public function processCue(infoObject:Object):void {
			trace("-- processCue:");
	
			switch (infoObject.name) { 
 			 	case "TEXTZOOM" :  
					var texzoom:TextPack = new TextPack();
		 			texzoom.zoomObject(infoObject);
 					break; 
				 case "VP" : 
		 			Vars.finiteState = "VP";
					new Panorama(infoObject);
					break; 
			 	case "XP" : 
		 			Vars.finiteState = "XP";
					break; 
 		 		case "REPERE" : 
					var texnav:TextPack = new TextPack();
		 			texnav.navText(infoObject);
					break; 
 				default : 
 					trace("      --> unknown cuepoint"); 
			}
		}
Sorry it's a lot of code, but it's a huge application.
I must say that if I run just the code you gave me on a flash9 pano, it's all fine. It's just when I use it inside my Panorama class (i.e. not instanced directly by the FLA) that I get all that mess.
Can you make sense of those messages?

Thanx a million
Silvano
bizmillah
Posts: 12
Joined: Fri Sep 07, 2007 5:16 pm

Thu Oct 11, 2007 4:32 pm

Thomas,

forget my last reply. I gave up on porting the application to AS3. I spent over a month and wrote over 2000 lines of code in 12 packages and still can't figure out how to make it all work. I have a deadline in 4 weeks and need to get it running, so I'll just finish it off in AS2, which I know well, and then will think about converting, if ever, next year.

I will come soon to haunt you again, 'coz I'm still having problems in AS2, displaying the pano at the right size. It seems that it ignores my mc._width and _height. I'll submit a new post for that.

thanx
Silvano
Post Reply