Mask for flash

Specific Q&A about the new Flash export
Locked
jcg
Posts: 5
Joined: Thu Jun 14, 2007 11:39 pm

Wed Jun 20, 2007 10:33 pm

I am having trouble importing the swf I create with Pano2qtvr and then having it appear behind a mask (scripted). Does anyone have any hints as to how to accomplish this?

Thanks for any help.
baoputzi
Posts: 14
Joined: Tue Sep 19, 2006 10:28 am
Location: Cologne/Germany
Contact:

Thu Jun 21, 2007 8:32 pm

jcg wrote:I am having trouble importing the swf I create with Pano2qtvr and then having it appear behind a mask (scripted). Does anyone have any hints as to how to accomplish this?

Thanks for any help.
import the pano into a container on your root:

this flag is set to avoid double loading of the pano
var panoLoadFlag:Boolean;

//pano loading function

function loadPanoContainer(){
this.panoLoadFlag = true;

//now you can use any newly created movie clip either manually on the stage or dynamically on the run:
//this.createEmptyMovieClip("pano_mc",10);

var loadListener:Object = new Object();

loadListener.onLoadProgress = function (target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void{
this.my_pb.setProgress /*for this to happen drag a progressbar from the components library to your stage and place it and name it
*/
(numBytesLoaded,numBytesTotal);//progress bar in manual mode
this.my_pb._alpha = 100-my_pb.percentComplete;
};

loadListener.onLoadInit = function(target_mc:MovieClip){
target_mc._x = 0;
target_mc._y = 85;
};
loadListener.onLoadComplete = function(target_mc:MovieClip){
this.my_pb._visible = false;
this.navigation_mc.panoOn = false;
target_mc.stop();
target_mc._visible = false;


};

var loader_mcl:MovieClipLoader = new MovieClipLoader();
loader_mcl.addListener(loadListener);
loader_mcl.loadClip("swf/panoContainer.swf",this.pano_mc);

}
// here we finally load the pano, but only if it was not loaded before

if (this.panoLoadFlag == false || this.panoLoadFlag == undefined){
this.loadPanoContainer();

}
//end of Pano loading function

so you have your pano now use pano_mc.setMask(myMask_mc) and your are done.

Most things happen if you do not load the pano onto a manually created mc on your stage. Due to the depths management of flash. If you just use insert new symbol movieclip and drag this one from your library to your stage and name it pano_mc your not in trouble with depths and can mask your pano as you wish.
jcg
Posts: 5
Joined: Thu Jun 14, 2007 11:39 pm

Sat Jun 23, 2007 4:20 pm

thanks, the only add I had to make to get it to work was

pano_mc._lockroot = true;
Blake
Posts: 1
Joined: Sat Jul 07, 2007 9:44 pm

Sat Jul 07, 2007 9:47 pm

I am looking for a solutions for masking as well - I attempted to use your method and could not get it to work... any chance you could post a FLA for use... please... TIA - Blake.
landrvr1
Posts: 19
Joined: Fri Jun 08, 2007 4:09 pm

Mon Jul 09, 2007 9:56 pm

Blake wrote:I am looking for a solutions for masking as well - I attempted to use your method and could not get it to work... any chance you could post a FLA for use... please... TIA - Blake.
Okay, I've worked out a method that is perfect for me. I call the mask from a different point than within the actionScript used to call the .swf pano files.

I have a movieClip called mcRenderings. This is my starting point that I'll be dumping things into.

I have second movieClip called VR. This is the clip where I'm loading my pano .swf files.

I have a third movieClip called mask_mc. This is my mask, haha!

In mcRenderings I have a frame of actionScript that reads:

Code: Select all

this.attachMovie("VR","VR",10);

this.attachMovie("mask_mc","mask_mc",20);

VR.setMask(mask_mc);
This is doing 3 things. #1 it's loading my main pano movie called VR (in my library and NOT an external swf file). #2 loading my mask at a higher level. #3 setting the mask so that it's connected to the VR clip.

In VR (my main pano movie), I've got two actionScript layers. The first is this:

Code: Select all

this._x=0
this._y=0 
Why is that important? Well, the Panos created by Pano2QTVR put the origin point in it's own location, and rather than fiddle about I'm reorienting them to a 0,0 origin. Necessary? Maybe, maybe not, but why take chances? haha.

The 2nd actionScipt layer contains my main pano code:

Code: Select all

var radar_offset:Number=0;
var currentid:Number=0;
var topid:Number=1;
var hotspots:Array=new Array;

// Create container movieclip
var vr:MovieClip = createEmptyMovieClip("vr", 1);
// prevent access to "real" root
vr._lockroot=true;

function clearHotspots() {
	var mc:MovieClip;
	var i:Number;
	for (i=0;i<hotspots.length;i++) {
		mc=hotspots[i];
		mc.removeMovieClip();
	}
	hotspots=new Array();
}

function loadPanorama(id:Number) {
	// Create a Movieclip loader
	var myLoader = new MovieClipLoader();
	var myListener = new Object();
	
	// remove old Hotspots
	clearHotspots();

	myListener.onLoadStart = function () {
		var filename:String;
	// Set the dimentions and position of the pano
		vr.window_width=500;
		vr.window_height=398;
		vr.window_x=-68;
	  	vr.window_y=-207.8;
	// change autorotation  
	  	vr.autorotate=0.5;
	  	vr.autorotate_delay=20;
		
		// add a preview bar...
		var my_fmt:TextFormat = new TextFormat();
		my_fmt.bold = true;
		my_fmt.font = "Arial";
		my_fmt.size = 12;
		my_fmt.color = 0xffffff;
		createTextField("pretxt",10,170,40,200,20);
		pretxt.setNewTextFormat(my_fmt);
		pretxt.selectable = false;
		pretxt.text = "Loading...";
		createEmptyMovieClip("prebar",21);
	};

	myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) {
		// update progress bar
		var x1:Number,x2:Number,y1:Number,y2:Number;
		pretxt.text = "Loading... " + Math.floor(100*loadedBytes/totalBytes) + " %";
		prebar.clear();
		prebar.beginFill(0x0000FF, 30);
		prebar.lineStyle(2, 0x000080, 100);

		x1=pretxt._x;
		x2=x1 + 180 * loadedBytes/totalBytes;
		y1=pretxt._y+20;
		y2=y1+10;
		
		_root.prebar.moveTo(x1, y1);
		_root.prebar.lineTo(x2, y1);
		_root.prebar.lineTo(x2, y2);
		_root.prebar.lineTo(x1, y2);
		_root.prebar.lineTo(x1, y1);
		_root.prebar.endFill();
		
	};
	
	myListener.onLoadComplete = function () {
		// remove progress bar
		pretxt.removeTextField();
		prebar.removeMovieClip();
	};

	myListener.onLoadInit = function () {
		setupPanorama(currentid); 
		// Add another hotspot to position pan 0, tilt -90 (nadir) without rollover effect
		var hs_p2q:MovieClip=attachMovie("pano2qtvr_lib","hs_textmc2",10200);
		hs_p2q.onRelease=function() {
			getURL('http://www.pano2qtvr.com','_blank');
		}
		vr.pano.addHotspot('p2q',0,-90,hs_p2q);
		// add hotspots to a list to clear them
		hotspots.push(hs_p2q);
		compass.fov._visible=true;
	};

	// add the Listener 
	myLoader.addListener(myListener);
	
	// set the parameters for the different panoramas
	if (id==1) {
		filename="support/StateFarm-Office.swf";
		radar_offset=0;
		compass._x=map._x+map.bt1._x;
		compass._y=map._y+map.bt1._y;
	}
	if (id==2) {
		filename="support/StateFarm-Welcome.swf";
		radar_offset=180;
		compass._x=map._x+map.bt2._x;
		compass._y=map._y+map.bt2._y;
	}

	// remove the radar during loading
	compass.fov._xscale=0;
	compass.fov._yscale=0;
	compass.fov._visible=false;

	// ... and finally load the pano!
	myLoader.loadClip(filename, vr); 
	currentid=id;
	
}




// add the map
var map:MovieClip=attachMovie("map","map",20005,{_x:-202,_y:-207.8});

// connect the buttons in the map
map.bt1.onPress=function () {
	loadPanorama(1);
}
map.bt2.onPress=function () {
	loadPanorama(2);
}


// ... and the rader is even higher...
var compass:MovieClip=attachMovie("compass_lib","compass",20010,{_x:60,_y:200,_alpha:50});

compass.fov._xscale=0;
compass.fov._yscale=0;
compass._visible=true;
compass.fov._visible=false;

// update the shape of the rader on each frame
onEnterFrame=function() {
	compass.fov._rotation=-(vr.pano.getPan()+radar_offset);
	compass.fov._xscale=100*Math.tan(vr.pano.getFov()*Math.PI/360);
	compass.fov._yscale=100*Math.cos(vr.pano.getTilt()*Math.PI/180);
}

// load the pavilion pano first
loadPanorama(2);
No surprises here; though I don't use hotspots or a border - even though I left the hotspot code in. Sloppy, I know....

It's important to remember that your linkages be set for each of the movieClips involved. Other than that, this is pretty straightforward.
Locked