Flash AS3 Preloader error: 1120 access of undefined property, preloader? - actionscript-3

I'm a complete newbie to this, I've been watching tons of tutorials, reading tutorials, reading the Adobe site, etc... The last time I programmed was BASIC on Apple IIe...
I'm trying to create a preloader that my html page will link to, and when the main .swf file (Portfolio.swf) is loaded, it will display and stop (it's a print swf, so I don't want it to "Play" at 24 frames/sec.)
I have errors in my AS3 of 1120, which I will copy the code here:
stop();
var loader : Loader = new Loader ();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest ("Portfolio.swf"));
function progressHandler(e:ProgressEvent) {
var percent:Number=Math.round(e.bytesLoaded*100/e.bytesTotal);
preloader.gotoAndStop(percent);
}
function completeHandler(e:Event) {
this.addChild(loader);
this.removeChild(preloader);
}
And here's what I uploaded to my site so far to test:
http://krisbunda.com/templates/portfolio/Portfolio.html
as you can see, it just loops the progress bar, and doesn't load the "Portfolio.swf" file afterward. The actual "Portfolio.swf" can be viewed on this page:
[actually, I'm new, can't post more than 1 hyperlink... you can find the Portfolio on the root of my site.]
it takes a while to download the 6MB+ file, which is why I would like a preloader.
Thanks for your help!

I finally figured it out, albeit the code has evolved (devolved?) to something different.
I'm not at home to copy the AS3 from my workstation, but here's a link to see the code working as I intended it:
http://krisbunda.com/images/portfolio/Portfolio.html
send me a message if you are having a similar problem and would like the AS3 code pasted here.

Related

AS3 On video end transfer to a new SWF?

I'm trying to make it so once my my video ends the player will be moved onto a new SWF.
Here's the code I created
import fl.video.VideoEvent;
stop();
BackgroundVid.addEventListener(Event.COMPLETE, Menu_Screen);
function Menu_Screen(event:MouseEvent):void
{
var Menu_Screen_Loader = new Loader();
Menu_Screen_Loader.load(new URLRequest("Menu_Screen.swf"));
addChild(Menu_Screen_Loader);
}
Can't figure out why it's not booting properly.
Ok, first of all fix the mistake in the event handler. You are saying that the Event expected is a MouseEvent, where as it will in fact be a plain old Event.
Then if it still doesn't work, you'll need to furnish a bit more info regarding what isn't happening. What do you mean by booting properly. Is your video playing?

Remove SWF file after loading a Different SWF file using "Loader" in Flash (AS3)

I am trying to load multiple swf files. But the problem is that whenever I load them (back and forth; vice-versa), my file keeps on slowing down. I looked a solution from the internet, such as using "unload" and "removeChild" but I can't get a clear solution and I don't know where to put it. Any help is very much appreciated..Here's my code on how I load my swfs:
MainMenu.swf:
//***************CLICK GALLERY*********************//
Gallery_btn.addEventListener(MouseEvent.CLICK, Gallery);
function Gallery(event:MouseEvent):void{
var ldr1:Loader=new Loader();
ldr1.load(new URLRequest("Gallery.swf"));
addChild(ldr1);
}
Gallery.swf:
//***************CLICK QUIT******************//
Quit_btn.addEventListener(MouseEvent.CLICK, Quit);
function Quit(event:MouseEvent):void{
var ldr1:Loader=new Loader();
ldr1.load(new URLRequest("MainMenu.swf"));
addChild(ldr1);
}
You need to use removeChild and remove every listener. You can unload swf by calling unload on your loader or unloadAndStop.
You can read this article for more information.
UnloadAndStop from Adobe
Unload SWF

How to play two swf files in as3

hai i want play two swf files in my action script project.In this two files one swf file works on the detection face in front of the system.Other swf plays the flv file.when face is detected player must be stooped if not player must be plays the flv file.
I know how to load the swf file but i cant handle the functionality regarding starting and stoping player.
the snippet of code shows how can i load external swf file .and i will explain each line of code in comments
public function videos(view:Sprite)
{
this.box = view;//IT GETS Sprite object from other class because of need to display the player also.
request = new URLRequest("Untitled-1.swf");
currentSWF=new MovieClip();
loader= new Loader();
loader.load(request);
box.addChild(loader);
currentSWF = MovieClip(loader.content);
loader.addEventListener(Event.COMPLETE,loadComplete);
//addChild(loader);
currentSWF.gotoAndPlay(1);//when i put this line of code in comments it plays the external swf also.
}
I hope u understand my doubt .can any one explain how to handle my things .i am new to this action script.please help me
Loaded files automatically play, unless you tell them explicitely not to. You’ll have to listen to the Event.INIT event, and stop the movie there:
loader.AddEventListener(Event.INIT, initLoader);
function initLoader (event:Event)
{
MovieClip(event.currentTarget.content).stop();
}
This will stop the movie before it is attached to the stage, and before it starts playing—so it won’t do that unless you start it again.
Note that you shouldn’t access loader.content in any way before the INIT or COMPLETE events, as it’s very likely that the content isn’t loaded then. As such you should put all your manipulating actions into the COMPLETE event:
box.addChild(loader);
loader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete (event:Event)
{
// Now it’s safe to access the `content` member:
currentSWF = MovieClip(loader.content);
// Of course this one would play the movie again, so you probably want
// to call that later on a button click or something.
currentSWF.gotoAndPlay(1);
}

Issue loading AS2 .swf that uses XML into AS3 .fla

I'm making a website for a client where they purchased a flash template that was written in "AS 1.0 & AS 2.0" and then asked me to add a googlemap to the contact us page. However, the googlemap API only works in AS3. My options were to translate the entire website to AS3 OR to make an AS3 file that imported the AS2 website and then added the googlemap bit.
I decided to go with option 2 since it seemed easier...
Anyway, I'm using the Loader class in the AS3 file.
var myLoader:Loader = new Loader(); // create a new instance of the Loader class
var url:URLRequest = new URLRequest("main_v8.swf"); // in this case both SWFs are in the same folder
myLoader.load(url); // load the SWF file
addChild(myLoader);
The problem is the AS2 swf file uses XML to load the background images. It works on its own but when loaded into the AS3 file the background images do not appear. All the buttons and external links work, its just the loading of the XML.
I've been looking all over for help on this and while there are lots of people with issues playing AS2 swf in AS3 I couldn't find anything to help with this.
Any advise or solutions would be appreciated!
Thanks!
Havent face such a problem but, if you find out the problem you ca solve it. You can check some conditions:
check network for , does xml loaded. (might be crossdomain problem)
check if images loaded. ( as3 security problem)
check as2 file really inits. ( you can use as3 bridge to as2)

AS3: Getting information from an externally loaded SWF

So I have an SWF that I've made and I need to appened some instructions to the beginning of the project. I figured the easiest way to do this was to make the animation in a separate SWF then import it to the start of the first one. My problem is that I can't find a reliable way to tell when the first SWF is finished playing. I've googled the heck out of this but I can't seem to find anything that works. For some bizarre reason, no matter what I do the program seems to think that the external SWF only has 2 frames, if I put an ENTER_FRAME listener and trace externalSWF.currentFrame I get "1, 1, 2, 2, 2, 2, 2, 2..." My code looks something like this.
var ldr = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
ldr.load(new URLRequest("Instructions.swf"));
function loaded(e:Event){
trace("Loaded");
var extSwf = ldr.content as MovieClip;
addChild(extSwf);
trace(extSwf.totalFrames);//Returns 2
}
Has anyone else had similar problems with external SWFs?
Also, for the record, the external SWF plays properly when I add it as a child. The problem is removing it from the stage when it's done playing. It's interactive so I can't just do a frame count.
Edit: So I tried doing a getQualifiedClassName() call on extSwf and I got "Instructions_fla::MainTimeline_Preloader_" which could explain the frame discrepency. How can I have access to the actual timeline?
To SWFs can communicate with each other via SharedObject.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html
So I found the solution to the problem. Like I said in the edit, I was getting "Instructions_fla::MainTimeline_Preloader_" as the QualifiedClassName so I googled that and found someone saying that Flash CS5 exports your SWFs with a preloader by default so that was what was being attached to extSwf and not the MovieClip itself. The way to fix it is to go into File>Actionscript Settings>Library Path, and change Default linkage to "Merged Into Code". This appears to only happen in CS5. I found the solution here: http://blog.flash-core.com/?p=142