FLASH AS3 Preloader experiment

Using Pano2VR/Object2VR SWF files with your own Flash projects
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

Hi all,

I'm experimenting a bit with the possibilities to load Pano2VR .swf's into regular Flash files using the AS3-instructions Thomas provided.
Just to see if it would work I made an AS3 preloader as shown on http://www.gotoandlearn.com, and although I'm all thumbs with Action Script it works, well.....kinda.
For instance, the full-screen button inside the preloaded Pano2VR pano works (to my surprise), but it doesn't scale the pano itself, only the Flash window. And I see lots of error notifications on opening the pano, even though it appears to work well.

Here's a link to an experimental version:
http://tinyurl.com/Pano2VR-AS3preloader

Any suggestions as to what I might have done wrong?
Thanks in advance!

Erik
Last edited by erik leeman on Wed Jan 13, 2010 10:51 pm, edited 3 times in total.
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

Correction: the full screen button does scale the panorama, but only to the width of the screen.
So it does work, but not entirely the way it should.

Here are some of the error notifications I get:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PanoCube/init()

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PanoCube/doRollOut()

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PanoCube/redrawCursor()

Erik
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

And here's the Action Script:

Code: Select all

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

var loader:Loader = new Loader();
var url:String = "../SWF/09-11-01-FrankDekkers-02-04-1024x768.swf";
var urlReq:URLRequest = new URLRequest(url);
var vr:MovieClip;

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
loader.load(urlReq);

laadindicator.width = 0;
percent.text = "0";

addEventListener( Event.ENTER_FRAME , initPanorama);
loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, finished_loading);
loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);

function loop(e:ProgressEvent):void
{
	var perc:Number = e.bytesLoaded / e.bytesTotal;
	percent.text = Math.ceil(perc*100).toString();
	laadindicator.width = perc * 400;
}

function done(e:Event):void
{
// getting rid of the preloader remnants
	removeChildAt(0);
	removeChildAt(0);
	removeChildAt(0);		
	removeChildAt(0);
	removeChildAt(0);
	removeChildAt(0);
	removeChildAt(0);
	removeChildAt(0);
 	percent = null;
	laadindicator = null;
// ready to boogie!

	addChild(loader);
}


function finished_loading (e:Event) {
}

function initHandler(event:Event):void {
	trace("initHandler: " + event);
	vr = MovieClip(loader.content);

//	vr.isFlash10=false; // Disable Flash 10 rendering if the container is Flash 9
	vr.isFlash10=true;
}

function initPanorama(e:Event) {
	if ((vr!=null) && (vr.pano!=null)) {
		removeEventListener(Event.ENTER_FRAME , initPanorama);
		vr.pano.setWindowSize(1000,540);
		vr.pano.setWindowPos(0,0);
	}
}
User avatar
shinodem
Posts: 24
Joined: Wed Jan 13, 2010 12:41 pm
Location: Russia, Krasnodar

advice from web designers) - then you create a site check it in different browsers =)
in opera no errors and all work :wink:

oh and please then you do panorama in full page, think about users who not have high end computers.
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

Ehhh...It's just an experiment to see if I can make it work, so I can use the method for more serious applications if the need should arise :)
I tried it in Firefox, Opera and Safari (for WinXP), all behave the same as far as I can tell.

Cheers!

Erik
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

Actually, when I think about it, it shouldn't scale at all when going to full screen.
Skin elements like buttons should not change in size, and here they obviously do.
So although the Pano2VR full screen button works as such from within a Flash preloader, it only scales the pano itself to fit the screen, but it doesn't actually make it 'Full screen'.

Now for a solution (if there is one).

Cheers!

Erik
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

About the 'enclosed' preloaded pano .swf not going full screen properly:
A quote from http://blog.deconcept.com/swfobject/#whyitsbetter
Some methods of Flash satay don’t stream the Flash movie to the player – So this method may require ‘holder’ swf movies that your movie is loaded in to.This makes passing variables from FlashVars parameters a hassle and make it a pain to maintain Flash content as you now have twice as many swf files floating around your web server.
Could this be the problem? FlashVar parameters from the HTML/JavaScript code not reaching the Pano2VR .swf?
Then the Pano2VR .swf doesn't know it is allowed to go full screen, so it doesn't.
Hmmm.... if so, what to do about it?

Erik
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

I just found that I can automatically switch to full screen by using my preloader.
It works in the Stand Alone Flash player, but sadly not on-line in a browser window : (

I added

Code: Select all

import flash.display.Stage;
import flash.display.StageDisplayState;
and

Code: Select all

stage.displayState = StageDisplayState.FULL_SCREEN;
to the code above, and now the pano window goes full screen automatically in the Stand Alone Flash player.
Alas the pano itself still doesn't want to expand with the window.

Erik
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

Yesss, another small step!
By adding

Code: Select all

vr.pano.setWindowSize(stage.stageWidth,stage.stageHeight);
the pano automatically fills the entire screen in a Stand Alone player, full screen at last!
Now the on-line version...
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

Made a few changes, and now full screen mode works on-line too.
Not entirely as it should though, because I did something Adobe doesn't want me to do.
So I get this on opening the page:
SecurityError: Error #2152: Full screen mode is not allowed.
at flash.display::Stage/set displayState()
at AS3FP10externalflashpreloaderperc_fla::MainTimeline/initPanorama()
But if you ignore that the page loads normally, and the full screen button works, Yes!
Would be nice if I manage to get rid of that security hiccup ;)

Erik
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

Great! Got rid of the security error by adding a conditional loop that detects FullScreen.
So now it works on-line too, but not 100% reliable yet :x
Sometimes it is necessary to reload the page to get a proper full screen, and I still get those irritating
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PanoCube/doRollOut()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PanoCube/redrawCursor()
Mdholl
Posts: 158
Joined: Sat May 09, 2009 11:43 am

Good luck!
Hope you will reach this aim. :)
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

:lol: Thanks!

Let me explain what my goal is:
I want to be able to silently load a group of panos in the background while an introduction (an animation and/or a video) is playing.
When loading is complete those panos must keep still in the background, waiting for their turn to step into the spotlight, one at the time.
Sounds simple enough, but this is, as yet, the illusive part of my quest.

I don't get any of those pesky PanoCube/doRollOut() PanoCube/redrawCursor() etc. errors if I load a pano and let it take over the stage straight away. Preloading as such is not the problem, it's the 'Wait until I tell you to show up'-bit that gives me headaches.
AND the unreliable switch to full screen of course.

So in this first simple test I want my own loading counter to finish at 100%, and THEN the pano should become active and visible, ready for (almost) immediate use. If I (ever) manage to get that working I want to try pre-loading two panos, to see if I can control them on the stage like I want to.

Help surely would be appreciated!

Cheers!

Erik
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

I've learned a few useful things about building Flash (AS3) preloaders for Pano2VR panos over the weekend : )
One of those things is that (to my surprise) you can load two (or perhaps even more) panos at once, one over the other.
Then you can control their individual visibility and/or transparency through the ActionScript API.
So, for instance, you can make the one on top semi-transparent so you can see both of them at the same time.
Or you can toggle the top one on-and-off by pressing a button or something.
Nice if you want users to be able to compare several states of the same panorama or interior.
Both panos pan and zoom perfectly in sync by using the keyboard, but sadly the mouse only controls the topmost one.
Even so, it's not difficult to imagine useful and creative applications for this possibility!

I'll make an overview of what I found out about some of the API parameters, their documentation seems a bit 'limited' as far as I can tell.

Cheers!

Erik
erik leeman
Posts: 470
Joined: Sat Sep 09, 2006 10:51 am
Contact:

Problem largely solved :D

See http://tinyurl.com/Pano2VR-Stack-of-Two-Switch for an example.
I still have to test fullscreen reliability though, but at least now I know what I was doing wrong.
Too bad no one could (or bothered to) tell me, it probably would have saved me an awful lot of time.

Erik
Post Reply