Getting the MovieClip

Using Pano2VR/Object2VR SWF files with your own Flash projects
Post Reply
mediaXpert
Posts: 2
Joined: Wed Mar 10, 2010 10:40 pm

Getting the MovieClip

Post by mediaXpert » Wed Mar 10, 2010 10:45 pm

Hi, using the ActionScript code from the site doesn't work because you cannot convert a DisplayObject into a MovieClip (even though the code example on Garden Gnome is copied from Adobe). All you get back is a null reference. So I figured out how to find the PanoPlayer like this:

var vr:MovieClip = new MovieClip();
vr.addChild(loader.content);
addChild(vr);
var pano:MovieClip = MovieClip(vr.getChildAt(0));

But when I try to do this:
trace( pano.getPan() );

It says "Error #1069: Property getPan not found on PanoPlayer and there is no default value."

How can I get from the PanoPlayer object to the getPan() method?

Thanks!

mediaXpert
Posts: 2
Joined: Wed Mar 10, 2010 10:40 pm

Re: Getting the MovieClip

Post by mediaXpert » Thu Mar 11, 2010 9:10 pm

Took me a while to figure out how to get the actual player and access the methods. Here is my version for a Flash movie I am going to run inside of Director and make getPan() calls to:

Code: Select all

package {
	import flash.display.*;
	import flash.events.TimerEvent;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.utils.Timer;
	
	public class VRLoader extends Sprite {
		var loader:Loader;
		var vr:MovieClip;
		var urlReq:URLRequest;
		var loaded:Boolean;
		var panoPlayer:MovieClip;
		
		public function VRLoader():void
		{
			// testing only
			loadFile("../../Gettysburg/Dev/Project/Interactive/SpecQTVRFiles/1stMN_out.swf");
		}
		
		public function loadFile(url:String):void
		{
			loaded = false;
			loader = new Loader();
			urlReq = new URLRequest(url);
			initListeners();
			
			loader.load(urlReq);
			//addChild(loader); // no need to add your swf directly to the stage
		}
		
		public function getPan():Number
		{
			if (loaded) {
				// pan = '<panoclip>.pano.getPan()'
				return panoPlayer.pano.getPan();
			} else {
				return -1;
			}
		}
		
		// This is done after the swf is loaded.
		public function finishedHandler (e:Event) {
		  //trace("finishedHandler: " + e);
		}
		
		public function initHandler(e:Event):void {
			//trace("initHandler: " + e);
			//var vr:MovieClip = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip' does NOT work
			
			vr = new MovieClip();
			vr.addChild(loader.content);
			addChild(vr);
			
			// once the 'DisplayObject' is a child of vr it can be converted to a 'MovieClip'
			panoPlayer = MovieClip(vr.getChildAt(0));
			
			// call initPanorama every frame
			addEventListener( Event.ENTER_FRAME , initPanorama);
		}
		
		public function initListeners():void {
			// Tell the loader to call 'finished_loading' after the swf is loaded.
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishedHandler);
			loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
		}
		
		public function initPanorama(e:Event):void {
			// check if the panorama object is available and initialized
			if ((vr != null) && (panoPlayer.pano != null)) {
				removeEventListener( Event.ENTER_FRAME , initPanorama );
				
				loaded = true;
				panoPlayer.pano.setWindowSize(320,240); // resize the window
				//panoPlayer.pano.setWindowPos(200,200); // reposition
				
				// test that we can get to our pan '<panoclip>.pano.getPan()'
				var pan:Number = getPan();
				if (pan >= 0){
					trace("initPanorama Pan: " + pan);
				}
			}
		}

	}
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest