punstc
09-16-2008, 05:32 PM
here's my main movie code. from the movie that is being loaded in by the preload movie.
import flash.net.URLRequest;
import flash.events.*;
import flash.display.*;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizing);
stage.dispatchEvent(new Event(Event.RESIZE));
var movieLoader:Loader = new Loader();
var movieDisplayed:Boolean = false;
var movieToLoad:URLRequest;
var currentMovie:String = "home";
var newstxtFade:Tween;
var showstxtFade:Tween;
var newsTitleFade:Tween;
var showsTitleFade:Tween;
var newsScrollerFade:Tween;
var showsScrollerFade:Tween;
var newsbgFade:Tween;
var showsbgFade:Tween;
var latestFade:Tween;
var tw:Tween;
addChild(movieLoader);
movieLoader.y = 95;
fogScroll.cacheAsBitmap = true;
bg_mc.cacheAsBitmap = true;
function fadeOut() {
newstxtFade = new Tween(news_txt, "alpha", None.easeNone, news_txt.alpha, 0, .5, true);
showstxtFade = new Tween(shows_txt, "alpha", None.easeNone, shows_txt.alpha, 0, .5, true);
newsTitleFade = new Tween(news_title, "alpha", None.easeNone, news_title.alpha, 0, .5, true);
showsTitleFade = new Tween(shows_title, "alpha", None.easeNone, shows_title.alpha, 0, .5, true);
newsScrollerFade = new Tween(news_scroller, "alpha", None.easeNone, news_scroller.alpha, 0, .5, true);
showsScrollerFade = new Tween(shows_scroller, "alpha", None.easeNone, shows_scroller.alpha, 0, .5, true);
newsbgFade = new Tween(news_bg, "alpha", None.easeNone, news_bg.alpha, 0, .5, true);
showsbgFade = new Tween(shows_bg, "alpha", None.easeNone, shows_bg.alpha, 0, .5, true);
//latestFade = new Tween(latest, "alpha", None.easeNone, latest.alpha, 0, .5, true);
//trace(latest_txt.alpha);
}
function fadeIn() {
newstxtFade = new Tween(news_txt, "alpha", None.easeNone, news_txt.alpha, 1, .5, true);
showstxtFade = new Tween(shows_txt, "alpha", None.easeNone, shows_txt.alpha, 1, .5, true);
newsTitleFade = new Tween(news_title, "alpha", None.easeNone, news_title.alpha, 1, .5, true);
showsTitleFade = new Tween(shows_title, "alpha", None.easeNone, shows_title.alpha, 1, .5, true);
newsScrollerFade = new Tween(news_scroller, "alpha", None.easeNone, news_scroller.alpha, 1, .5, true);
showsScrollerFade = new Tween(shows_scroller, "alpha", None.easeNone, shows_scroller.alpha, 1, .5, true);
newsbgFade = new Tween(news_bg, "alpha", None.easeNone, news_bg.alpha, 1, .5, true);
showsbgFade = new Tween(shows_bg, "alpha", None.easeNone, shows_bg.alpha, 1, .5, true);
//latestFade = new Tween(latest, "alpha", None.easeNone, latest.alpha, 1, .5, true);
//trace(latest_txt.alpha);
}
function resizing(e:Event) {
bg_mc.x = stage.stageWidth/2 - bg_mc.width/2;
bg_mc.y = 0;
title_mc.x = stage.stageWidth/2 - title_mc.width/2;
title_mc.y = 17;
home_btn.x = stage.stageWidth/2 - home_btn.width/2 - 420;
home_btn.y = 71;
bio_btn.x = stage.stageWidth/2 - home_btn.width/2 - 340;
bio_btn.y = 71;
pics_btn.x = stage.stageWidth/2 - home_btn.width/2 - 200;
pics_btn.y = 71;
video_btn.x = stage.stageWidth/2 - video_btn.width/2 + 235;
video_btn.y = 71;
contact_btn.x = stage.stageWidth/2 - contact_btn.width/2 + 315;
contact_btn.y = 71;
link_btn.x = stage.stageWidth/2 - link_btn.width/2 + 430;
link_btn.y = 71;
news_txt.x = 17;
news_txt.y = 200;
news_bg.x = 17;
news_bg.y = 200;
news_title.x = 17;
news_title.y = 184;
news_scroller.x = 225;
news_scroller.y = 185;
shows_txt.x = stage.stageWidth - shows_txt.width - 30;
shows_txt.y = 200;
shows_bg.x = stage.stageWidth - shows_txt.width - 30;
shows_bg.y = 200;
shows_title.x = stage.stageWidth - shows_txt.width - 30;
shows_title.y = 184;
shows_scroller.x = stage.stageWidth - shows_scroller.width - 10;
shows_scroller.y = 185;
latest_txt.x = stage.stageWidth/2 - latest_txt.width/2;
fogScroll.x = 0;
fogScroll.y = stage.height - fogScroll.height;
if (movieLoader !=null) {
movieLoader.x = stage.stageWidth/2 - movieLoader.width/2;
}
}
//button actions
home_btn.buttonMode = true;
home_btn.mouseChildren = false;
home_btn.button_txt.btn_txt.text = "home";
home_btn.addEventListener(MouseEvent.MOUSE_OVER, home_btn.over);
home_btn.addEventListener(MouseEvent.MOUSE_OUT, home_btn.out);
home_btn.addEventListener(MouseEvent.CLICK, goto);
bio_btn.buttonMode = true;
bio_btn.mouseChildren = false;
bio_btn.button_txt.btn_txt.text = "biography";
bio_btn.addEventListener(MouseEvent.MOUSE_OVER, bio_btn.over);
bio_btn.addEventListener(MouseEvent.MOUSE_OUT, bio_btn.out);
bio_btn.addEventListener(MouseEvent.CLICK, goto);
pics_btn.buttonMode = true;
pics_btn.mouseChildren = false;
pics_btn.button_txt.btn_txt.text = "photos";
pics_btn.addEventListener(MouseEvent.MOUSE_OVER, pics_btn.over);
pics_btn.addEventListener(MouseEvent.MOUSE_OUT, pics_btn.out);
pics_btn.addEventListener(MouseEvent.CLICK, goto);
video_btn.buttonMode = true;
video_btn.mouseChildren = false;
video_btn.button_txt.btn_txt.text = "video";
video_btn.addEventListener(MouseEvent.MOUSE_OVER, video_btn.over);
video_btn.addEventListener(MouseEvent.MOUSE_OUT, video_btn.out);
video_btn.addEventListener(MouseEvent.CLICK, goto);
contact_btn.buttonMode = true;
contact_btn.mouseChildren = false;
contact_btn.button_txt.btn_txt.text = "contact";
contact_btn.addEventListener(MouseEvent.MOUSE_OVER, contact_btn.over);
contact_btn.addEventListener(MouseEvent.MOUSE_OUT, contact_btn.out);
contact_btn.addEventListener(MouseEvent.CLICK, goto);
link_btn.buttonMode = true;
link_btn.mouseChildren = false;
link_btn.button_txt.btn_txt.text = "links";
link_btn.addEventListener(MouseEvent.MOUSE_OVER, link_btn.over);
link_btn.addEventListener(MouseEvent.MOUSE_OUT, link_btn.out);
link_btn.addEventListener(MouseEvent.CLICK, goto);
function goto(e:MouseEvent) {
if (e.currentTarget == bio_btn && currentMovie !="bio") {
fadeOut();
loadSWF(bioRequest);
currentMovie = "bio";
} else if (e.currentTarget == pics_btn && currentMovie != "photos") {
fadeOut();
//loadSWF(photoRequest);
currentMovie = "photos";
navigateToURL(new URLRequest("gallery.html"), "_self");
} else if (e.currentTarget == video_btn && currentMovie != "video") {
fadeOut();
loadSWF(videoRequest);
currentMovie = "video";
} else if (e.currentTarget == contact_btn && currentMovie != "contact") {
fadeOut();
loadSWF(contactRequest);
currentMovie = "contact";
} else if (e.currentTarget == link_btn && currentMovie != "link") {
fadeOut();
loadSWF(linkRequest);
currentMovie = "link";
} else if (e.currentTarget == home_btn && currentMovie != "home") {
fadeIn();
tw = new Tween(movieLoader, "alpha", Regular.easeOut, movieLoader.alpha, 0, .5, true);
tw.addEventListener(TweenEvent.MOTION_FINISH, unloadClip);
function unloadClip(e:TweenEvent = null) {
movieLoader.unload();
}
movieDisplayed = false;
currentMovie = "home";
}
}
var bioRequest:URLRequest = new URLRequest("bio.swf");
var photoRequest:URLRequest = new URLRequest("gallery.swf");
var videoRequest:URLRequest = new URLRequest("video.swf");
var contactRequest:URLRequest = new URLRequest("contact.swf");
var linkRequest:URLRequest = new URLRequest("links.swf");
function loadSWF(url:URLRequest) {
movieToLoad = url;
if (movieDisplayed == false) {
movieLoader.alpha = 0;
startLoad();
} else {
var tw:Tween = new Tween(movieLoader, "alpha", None.easeNone, movieLoader.alpha, 0, .5, true);
tw.addEventListener(TweenEvent.MOTION_FINISH, startLoad);
}
}
function startLoad(e:TweenEvent = null) {
movieLoader.load(movieToLoad);
movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, displayMovie);
}
function displayMovie(e:Event) {
movieLoader.x = stage.stageWidth/2 - movieLoader.width/2;
var tw2:Tween = new Tween(movieLoader, "alpha", Regular.easeOut, movieLoader.alpha, 1, .5, true);
movieDisplayed = true;
}
//text documents
var newsloader:URLLoader = new URLLoader();
newsloader.load(new URLRequest("news.txt"));
newsloader.addEventListener(Event.COMPLETE, newsComplete);
function newsComplete(event:Event):void {
news_txt.htmlText = event.target.data;
}
var showsloader:URLLoader = new URLLoader();
showsloader.load(new URLRequest("shows.txt"));
showsloader.addEventListener(Event.COMPLETE, showsComplete);
function showsComplete(event:Event):void {
shows_txt.htmlText = event.target.data;
}
var latestLoader:URLLoader = new URLLoader();
latestLoader.load(new URLRequest("latest.txt"));
latestLoader.addEventListener(Event.COMPLETE, latestComplete);
function latestComplete(event:Event):void {
latest_txt.htmlText = event.target.data;
}
Medyman
09-16-2008, 09:54 PM
Are you using a self-defined Document class? Or are you referring to one that's automatically created when you compile?
If you've written your own, post it here. I'll show you how to make the changes in one spot that'll get rid of the problems.
I just viewed Lee's new tutorial on preloading and a lot of what he says is misleading or at the very least incomplete. If you're using this preloading technique, you need to check that the Document class has loaded before you execute any actions. Bascially, in the preloding SWF, you're check to see if main_2.swf has loaded, not necessarily that it's been initiated. When the AS in main_2.swf fires, the stage has not yet been initiated. So, you're getting 1009 errors.
This happens because of the event listeners you're adding to the stage on Frame 1 of main timeline as well as on your scroll bars.
I'm guessing that you've not written your own document class based on how the SWF is set up. In which case, you would do this:
1. On your scrollbars
move the stage.AddEventListener inside the onClick function.
function onClick(e:MouseEvent)
{
knob_mc.startDrag(false, new Rectangle(track_mc.x+1,track_mc.y,0,track_mc.height - knob_mc.height));
stage.addEventListener(Event.ENTER_FRAME, update);
pressed = true;
stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
}
2. On the main timeline:
Add the following to the top:
isLoaded();
function isLoaded():void {
addEventListener(Event.ADDED_TO_STAGE, init);
};
function init(e:Event):void {
trace ("Document Class Fully Loaded");
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizing);
stage.dispatchEvent(new Event(Event.RESIZE));
};
That should do it.
Medyman
09-17-2008, 03:02 PM
Sure...
First, lets break down what's really happening with you're preloading. You're only preloading the .swf file. You're not initiating the .swf file. Initiating means having the assets within the .swf file available to manipulate. If you're familiar with JS, this is similar waiting until the DOM is ready to manipulate it. It's not enough that the .swf is visible, it's objects have to be on the display list.
If you know AS2, you'll recall that this is similar to onLoadComplete() and onLoadInit() of the MovieClipLoader class. onLoadComplete fired when the .swf was loaded and onLoadInit fired when the 1st frame of the .swf ran. What you need here is onLoadInit() and you're doing onLoadComplete()...so to speak.
So, what I asked you to add was a simple check.
addEventListener(Event.ADDED_TO_STAGE, init);
The ADDED_TO_STAGE event fires when (obviously) something is added to the stage. When something is added to the stage, it's in the display list and available to actions to manipulate.
So, this event will fire when the Document class (a.k.a. the main timeline, in this case) is loaded and initiated.
The problem you were having before was that the stage hadn't yet been initialized and you were adding event listeners to it. This makes sure that it is initialized, and then adds the event listeners.
Does that make sense?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.