alexstudio
October 16th, 2008, 05:04 PM
Like a lot of people I'm trying to make the transition from as2 to as3. So I'm going back and relearning all the things I know how to do in as2 like preloaders, events, loading external files, etc.
One of the things I'm trying to do is make a layout realign its self depending on the stage size.
This works fine in its own file but once I have my preloader load the file it breaks. I looked around online and only thing I've found so far is that its a big issue with scope, and I should try to avoid stage and root as much as I can.
So my question is what is the correct way to do this with external files? I'm also have a problem targeting objects or methods on the main time line from external movies, and the other way around too.
Here is the code if helps you understand it:
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
TWEEN CLASS
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
import gs.TweenLite;
import gs.easing.*;
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
FULLSCREEN FUNTIONALITY
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
stage.scaleMode = StageScaleMode.NO_SCALE;
var fsMode:Boolean = new Boolean;
fsMode = false;
fsBTN_mc.addEventListener(MouseEvent.CLICK, fsGo);
function fsGo (e:MouseEvent) {
if (fsMode==false) {
trace(fsMode);
stage.displayState = StageDisplayState.FULL_SCREEN;
fsMode=true;
}else{
stage.displayState = StageDisplayState.NORMAL;
trace(fsMode);
fsMode=false;
}
}
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
START NAVIGATION FUNCTIONALITY
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*************************************************
URL REQUESTS
**************************************************/
var rIndex:URLRequest = new URLRequest("index.swf");
var rAbout:URLRequest = new URLRequest("about.swf");
var rDemo:URLRequest = new URLRequest("demo.swf");
/*************************************************
FILE LOADER
**************************************************/
var myLoader:Loader = new Loader();
myLoader.load(rIndex); //Loads the frist page
myLoader.contentLoaderInfo.addEventListener(Event. OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(Progre ssEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event. COMPLETE,showLoadResult);
/*************************************************
LOADER FUNCTION CALL BACKS
**************************************************/
function showPreloader(evt:Event):void {
addChild(loadProgress_txt);
}
function showProgress(evt:ProgressEvent):void {
var Per:Number = Math.round((evt.bytesLoaded / evt.bytesTotal)*100);//Var that getsthe % loaded
loadProgress_txt.text = Per+"%";
lBar_mc.gotoAndStop(Per);
}
function showLoadResult(evt:Event):void {
removeChild(loadProgress_txt);
removeChild(lBar_mc);
container_mc.addChild(myLoader);
container_mc.play();
}
/*************************************************
LOADER FUNCTION RESET
**************************************************/
function resetLoader() {
container_mc.removeChild(myLoader);
loadProgress_txt.text = "0";
lBar_mc.gotoAndStop(1);
addChild(loadProgress_txt);
addChild(lBar_mc);
}
/*************************************************
URL REQUESTS
**************************************************/
index_mc.addEventListener(MouseEvent.CLICK, indexMC);
function indexMC(e:MouseEvent) {
resetLoader();
myLoader.load(rIndex);
}
about_mc.addEventListener(MouseEvent.CLICK, aboutMC);
function aboutMC(e:MouseEvent) {
resetLoader();
myLoader.load(rAbout);
}
demo_mc.addEventListener(MouseEvent.CLICK, demoMC);
function demoMC(e:MouseEvent) {
resetLoader();
myLoader.load(rDemo);
}
/*************************************************
ROLL OVER AND ROLL OUTs
**************************************************/
index_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverEvent);
index_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutEvent);
about_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverEvent);
about_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutEvent);
fsBTN_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverEvent);
fsBTN_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutEvent);
demo_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverEvent);
demo_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutEvent);
function rollOverEvent (e:MouseEvent) {
TweenLite.to(e.target, .5, {tint:0x0099FF, alpha:.5 })
}
function rollOutEvent (e:MouseEvent) {
TweenLite.to(e.target, .15, {tint:0x999999, alpha:1 })
}
function egg () {
trace("I have eggs")
}
import gs.TweenLite;
import gs.easing.*;
stage.align = StageAlign.TOP_LEFT;
//Setup
TweenLite.to(title_mc, 0, {y:150, alpha:0})
TweenLite.to(topMargin_mc, 0, {height:10, width:10, y:5, x:stage.stageWidth/2, alpha:0})
TweenLite.to(bottomMargin_mc, 0, {height:10, width:10, y:stage.stageHeight-5, x:stage.stageWidth/2, alpha:0})
TweenLite.to(rightCopy_mc, 0, {y:stage.stageHeight/2, x:stage.stageWidth/2 })
//Intro
TweenLite.to(title_mc, .5, {delay:1, y:60, alpha:1 /*onComplete:fuction*/})
TweenLite.to(topMargin_mc, 1, {delay:2, width:stage.stageWidth, ease:Bounce.easeOut, alpha:1})
TweenLite.to(bottomMargin_mc, 1, {delay:2, width:stage.stageWidth, ease:Bounce.easeOut, alpha:1})
//Item align
this.stage.addEventListener(Event.RESIZE, resizeHandler);
function resizeHandler(event:Event):void {
position();
}
function position(){
TweenLite.to(topMargin_mc, 0, {y:5, width:stage.stageWidth, x:stage.stageWidth/2})
TweenLite.to(bottomMargin_mc, 0, {y:stage.stageHeight-5, width:stage.stageWidth, x:stage.stageWidth/2})
TweenLite.to(rightCopy_mc, 0, {y:stage.stageHeight/2, x:stage.stageWidth/2 })
}
One of the things I'm trying to do is make a layout realign its self depending on the stage size.
This works fine in its own file but once I have my preloader load the file it breaks. I looked around online and only thing I've found so far is that its a big issue with scope, and I should try to avoid stage and root as much as I can.
So my question is what is the correct way to do this with external files? I'm also have a problem targeting objects or methods on the main time line from external movies, and the other way around too.
Here is the code if helps you understand it:
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
TWEEN CLASS
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
import gs.TweenLite;
import gs.easing.*;
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
FULLSCREEN FUNTIONALITY
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
stage.scaleMode = StageScaleMode.NO_SCALE;
var fsMode:Boolean = new Boolean;
fsMode = false;
fsBTN_mc.addEventListener(MouseEvent.CLICK, fsGo);
function fsGo (e:MouseEvent) {
if (fsMode==false) {
trace(fsMode);
stage.displayState = StageDisplayState.FULL_SCREEN;
fsMode=true;
}else{
stage.displayState = StageDisplayState.NORMAL;
trace(fsMode);
fsMode=false;
}
}
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
START NAVIGATION FUNCTIONALITY
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*************************************************
URL REQUESTS
**************************************************/
var rIndex:URLRequest = new URLRequest("index.swf");
var rAbout:URLRequest = new URLRequest("about.swf");
var rDemo:URLRequest = new URLRequest("demo.swf");
/*************************************************
FILE LOADER
**************************************************/
var myLoader:Loader = new Loader();
myLoader.load(rIndex); //Loads the frist page
myLoader.contentLoaderInfo.addEventListener(Event. OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(Progre ssEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event. COMPLETE,showLoadResult);
/*************************************************
LOADER FUNCTION CALL BACKS
**************************************************/
function showPreloader(evt:Event):void {
addChild(loadProgress_txt);
}
function showProgress(evt:ProgressEvent):void {
var Per:Number = Math.round((evt.bytesLoaded / evt.bytesTotal)*100);//Var that getsthe % loaded
loadProgress_txt.text = Per+"%";
lBar_mc.gotoAndStop(Per);
}
function showLoadResult(evt:Event):void {
removeChild(loadProgress_txt);
removeChild(lBar_mc);
container_mc.addChild(myLoader);
container_mc.play();
}
/*************************************************
LOADER FUNCTION RESET
**************************************************/
function resetLoader() {
container_mc.removeChild(myLoader);
loadProgress_txt.text = "0";
lBar_mc.gotoAndStop(1);
addChild(loadProgress_txt);
addChild(lBar_mc);
}
/*************************************************
URL REQUESTS
**************************************************/
index_mc.addEventListener(MouseEvent.CLICK, indexMC);
function indexMC(e:MouseEvent) {
resetLoader();
myLoader.load(rIndex);
}
about_mc.addEventListener(MouseEvent.CLICK, aboutMC);
function aboutMC(e:MouseEvent) {
resetLoader();
myLoader.load(rAbout);
}
demo_mc.addEventListener(MouseEvent.CLICK, demoMC);
function demoMC(e:MouseEvent) {
resetLoader();
myLoader.load(rDemo);
}
/*************************************************
ROLL OVER AND ROLL OUTs
**************************************************/
index_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverEvent);
index_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutEvent);
about_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverEvent);
about_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutEvent);
fsBTN_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverEvent);
fsBTN_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutEvent);
demo_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverEvent);
demo_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutEvent);
function rollOverEvent (e:MouseEvent) {
TweenLite.to(e.target, .5, {tint:0x0099FF, alpha:.5 })
}
function rollOutEvent (e:MouseEvent) {
TweenLite.to(e.target, .15, {tint:0x999999, alpha:1 })
}
function egg () {
trace("I have eggs")
}
import gs.TweenLite;
import gs.easing.*;
stage.align = StageAlign.TOP_LEFT;
//Setup
TweenLite.to(title_mc, 0, {y:150, alpha:0})
TweenLite.to(topMargin_mc, 0, {height:10, width:10, y:5, x:stage.stageWidth/2, alpha:0})
TweenLite.to(bottomMargin_mc, 0, {height:10, width:10, y:stage.stageHeight-5, x:stage.stageWidth/2, alpha:0})
TweenLite.to(rightCopy_mc, 0, {y:stage.stageHeight/2, x:stage.stageWidth/2 })
//Intro
TweenLite.to(title_mc, .5, {delay:1, y:60, alpha:1 /*onComplete:fuction*/})
TweenLite.to(topMargin_mc, 1, {delay:2, width:stage.stageWidth, ease:Bounce.easeOut, alpha:1})
TweenLite.to(bottomMargin_mc, 1, {delay:2, width:stage.stageWidth, ease:Bounce.easeOut, alpha:1})
//Item align
this.stage.addEventListener(Event.RESIZE, resizeHandler);
function resizeHandler(event:Event):void {
position();
}
function position(){
TweenLite.to(topMargin_mc, 0, {y:5, width:stage.stageWidth, x:stage.stageWidth/2})
TweenLite.to(bottomMargin_mc, 0, {y:stage.stageHeight-5, width:stage.stageWidth, x:stage.stageWidth/2})
TweenLite.to(rightCopy_mc, 0, {y:stage.stageHeight/2, x:stage.stageWidth/2 })
}