Skip to main content
Known Participant
September 13, 2011
Answered

preloader help pls

  • September 13, 2011
  • 2 replies
  • 1369 views

hi all i have a burning question which i really need an answer to,

basically i have a preloader and i want it to load each section when called with this code:

callback function////////////////////////////////////////////////////////////////////////////////////////////

caps_mc.btn_continue_mc.addEventListener(MouseEvent.CLICK, nextpls);

function nextpls(e:MouseEvent):void {
    MovieClip(parent.parent).nextSWF("startPage", parent);
}

the code above tells the preloader that it is finished with the startPage and in the preloader it should next load faq,

but i get an error saying that nextSWF is not a function when it clearly is,

is it even possible to use a preloader to load up swfs in this way??

preloader///////////////////////////////////////////////////////////////////////////////////////////////////////

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

var loadedSWF:Loader
var progressPercent:Number;

function startLoad(SWFName:String):void {
loadedSWF = new Loader();
loadedSWF.contentLoaderInfo.addEventListener(Event.COMPLETE, gameLoaded);
loadedSWF.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
loadedSWF.load(new URLRequest(SWFName+".swf"));
  

}
//track progress
function onProgressHandler(loadingProgress:ProgressEvent){

var percent:Number = loadingProgress.bytesLoaded/loadingProgress.bytesTotal;

progressPercent = Math.round((percent*100));
preload_mc.gotoAndStop(progressPercent);
preload_mc.myloadtext_txt.text=(progressPercent + " %")
preload_mc.myloadbar_mc.scaleX = percent;
preload_mc.mc_mask.height=(progressPercent * 3);
preload_mc.ofBytes_txt.text = loadingProgress.bytesLoaded + " bytes";
preload_mc.totalbytes_txt.text = loadingProgress.bytesTotal + " bytes";

}
  
function gameLoaded(e:Event):void{

removeChild(preload_mc);
this.addChild(loadedSWF);

loadedSWF.contentLoaderInfo.removeEventListener(Event.COMPLETE, gameLoaded);
loadedSWF.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler);
}
function nextSWF(whichSWFName, removeSWF){
    this.removeChild(removeSWF.parent);
    if(whichSWFName == "startPages"){
    startLoad("faq");
}

}
startLoad("startPages");

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

here is the error

TypeError: Error #1006: nextSWF is not a function.
at startPages_fla::MainTimeline/nextpls()[startPages_fla.MainTimeline::frame1:7]

if anyone can help i would be most grateful, i am hoping to be able to have a re-useable preloader

thanks in advance

fonzio

This topic has been closed for replies.
Correct answer kglad

is startPage() in frame 1 of your main swf's main timeline?

if so, what's the following trace() show:

caps_mc.btn_continue_mc.addEventListener(MouseEvent.CLICK, nextpls);

function nextpls(e:MouseEvent):void {

trace(MovieClip(parent.parent);
    MovieClip(parent.parent).nextSWF("startPage", parent);
}

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 13, 2011

is startPage() in frame 1 of your main swf's main timeline?

if so, what's the following trace() show:

caps_mc.btn_continue_mc.addEventListener(MouseEvent.CLICK, nextpls);

function nextpls(e:MouseEvent):void {

trace(MovieClip(parent.parent);
    MovieClip(parent.parent).nextSWF("startPage", parent);
}

fonzio1Author
Known Participant
September 13, 2011

hmm trace comes back will null

the way it goes is, i have a trial.swf

which is the preloader which loads start page in ok

on press of a button on start page i was hoping it would tell that preloader to go and relaunch but this time load ("faq"), i can use this code on a normal loader and everything will work fine the child is removed and another one loaded in, however the code itself needs to be in preloader form as the load takes a while to complete.

i do have some other code inside of the start page mc maybe this is affecting everything going correctly

its does this kind of check

stop();


import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.*;
import flash.display.*;
import flash.net.URLRequest;

var checks:Boolean = false;


// First claim  and place all of the capabilities values into vars for easy  code use below
warning_res_mc.visible = false;
version_check_mc.visible=false;
good_txt_mc.visible=false;
btn_flash_mc.visible=false;
btn_flash_mc.buttonMode=true;
btn_continue_mc.buttonMode=true;

var myrequest:URLRequest


btn_continue_mc.visible = false;

var version:String = Capabilities.version;
var language:String = Capabilities.language;
var os:String = Capabilities.os;
var screenDPI:Number = Capabilities.screenDPI;
var screenResolutionX:Number = Capabilities.screenResolutionX;
var screenResolutionY:Number = Capabilities.screenResolutionY;

// Then simply display in the dynamic text fields on stage
version_txt.text = "Flash Version: " + version;
language_txt.text = "Language: " + language;
os_txt.text = "Operating System: " + os;
screenDPI_txt.text = "Screen DPI: " + screenDPI;
screenResolution_txt.text = "Screen Resolution: " + screenResolutionX + " x " + screenResolutionY;


btn_flash_mc.addEventListener(MouseEvent.MOUSE_OVER, flashOver);

function flashOver(event:MouseEvent):void {
btn_flash_mc.play();
}
  
btn_flash_mc.addEventListener(MouseEvent.MOUSE_OUT, flashOut);
  
function flashOut(event:MouseEvent):void {
btn_flash_mc.gotoAndPlay(54);
}

btn_flash_mc.addEventListener(MouseEvent.CLICK, flashclick);

function flashclick(event:MouseEvent):void {
  
btn_flash_mc.gotoAndStop(1);
myrequest = new URLRequest("http://get.adobe.com/flashplayer/");
navigateToURL(myrequest);
btn_flash_mc.removeEventListener(MouseEvent.CLICK, flashclick);
}

var _fullInfo:String = Capabilities.version;
var _osSplitArr:Array = _fullInfo.split(' ');
var _versionSplitArr:Array = _osSplitArr[1].split(',');

/* declare the relevant infos */
var _osInfo:String = _osSplitArr[0];
var _versionInfo:Number = _versionSplitArr[0];


if (_versionInfo < 10){
version_check_mc.visible=true;
btn_flash_mc.visible=true;
btn_continue_mc.visible = false;
checks = true;

}

if (screenResolutionX > 800){
warning_res_mc.visible = true;
checks = true;
btn_continue_mc.visible = true;
}

if (checks != true){
good_txt_mc.visible = true;
btn_continue_mc.visible = true;
}

you see i am wanting to re-use the same preloader to load each swf as we go, although im not sure this is possible

thanks for your input

fonzio

kglad
Community Expert
Community Expert
September 13, 2011

trace just the parent and see if you get the loader.

kglad
Community Expert
Community Expert
September 13, 2011

both code snippets need to be on the main timelines of their swfs.

fonzio1Author
Known Participant
September 13, 2011

hi thanks for the reply

but no good im afraid

i tried moving the button to the main timeline also, but that had no effect still saying its not a function

hmm wondering what to do

i mean is it possible to do this via as

ive heard you can do it with classes but im even more noob with those

thanks

fonzio