package com { /** *@author - Subtropica Motion and Graphics * e-mail: wow.subtropica@gmail.com */ /* * This is the main class of the banner! */ //imports----------------------------- import com.footer.Footer; import flash.display.DisplayObject; import flash.display.Loader; import flash.display.MovieClip; import flash.display.StageAlign; import flash.display.StageDisplayState; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent; import flash.events.ProgressEvent; import flash.geom.Matrix; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext; import flash.text.TextFieldAutoSize; import gs.*; import gs.easing.*; import gs.plugins.*; //blur plugin activation TweenPlugin.activate([BlurFilterPlugin]); public class Main extends MovieClip { //xmls private const globalXmlLink:String = "xml/global.xml";//path to main xml of this site private var globalXml:XML;//global XML //MovieClips private var footer:MovieClip;//footer mc private var bg:MovieClip;//background mc private var snow:MovieClip;//snow mc private var year:MovieClip;//2011 year with candles mc private var title1:MovieClip;//title1 mc private var title2:MovieClip;//title2 mc private var colorScheme:MovieClip;//colorscheme mc //variables private var thisHeight:int;//height of greeting //classes private var Mask:Class;//mask class private var Bg:Class;//class background private var Snowing:Class;//snow class private var Stripes:Class;//class for bg lines private var Year:Class;//year 2011 with candles class private var Title1:Class;//title1 class private var Title2:Class;//title2 class private var ColorScheme:Class;//colorscheme class //loaders protected var urlLoader:URLLoader;//url load helper protected var contLoader:Loader;//assets loader public function Main() { super(); //if site is on the stage we call init function //if not we add event listener to catch event when site will be on the stage if(stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); //set main parameters of site stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; //add event listener on resize stage.addEventListener(Event.RESIZE, onResize); //start loading global XML getXml(globalXmlLink,loadGlobalXmlComplete); } protected function getXml(xmlUrl:String, completeFunc:Function):void//need for loading xml { //init urlLoader urlLoader = new URLLoader(); urlLoader.dataFormat = URLLoaderDataFormat.TEXT; //add event listener urlLoader.addEventListener(Event.COMPLETE, completeFunc); //start loading xml try{ urlLoader.load(new URLRequest(xmlUrl)); }catch(e:Error) { trace("can't get xml from " + xmlUrl); } } //start loading Xml private function loadGlobalXmlComplete(e:Event):void//function which is called when global xml was loaded { removeEventListener(Event.COMPLETE, loadGlobalXmlComplete); //init global xml globalXml = new XML(urlLoader.data); //start loading bg loadingAssets("assets/assets.swf"); } //loading assets----------------------------------- protected function loadingAssets(path:String):void { //init context var context:LoaderContext = new LoaderContext(true, ApplicationDomain.currentDomain); contLoader = new Loader(); //start preloader working //add event listeners //contLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, assetsLoadingProgress); contLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, assetsLoadingComplete); //start loading assets contLoader.load(new URLRequest(path), context); } //assets loading complete----------------- protected function assetsLoadingComplete(e:Event):void { //get classes from assets swf Mask = getClass(contLoader, "Mask"); Bg = getClass(contLoader, "Bg"); Snowing = getClass(contLoader, "Snowing"); Stripes = getClass(contLoader, "Stripes"); Year = getClass(contLoader, "Year"); Title1 = getClass(contLoader, "Title1"); Title2 = getClass(contLoader, "Title2"); ColorScheme = getClass(contLoader, "ColorScheme"); //init Banner work initBanner(); } //getting classes from assets-------------------- protected function getClass(loader:Loader, className:String):Class//need for getting classes from asset swfs { return loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class; } //init banner work private function initBanner():void{ if(globalXml.colorscheme[0].@enabled == "true"){ thisHeight = stage.stageHeight - 112; }else{ thisHeight = stage.stageHeight; } //init background initBg(); //init year with candles initYear(); //init title1 initTitle1(); //init title2 initTitle2(); //init footer initFooter(); //init snow if(globalXml.snow[0].@enabled == "true") initSnow(); //init color scheme if(globalXml.colorscheme[0].@enabled == "true") initColorScheme(); } //init Color Scheme private var activeColor:int = 1;//active color private function initColorScheme():void{ colorScheme = new ColorScheme(); colorScheme.name = "colorScheme"; colorScheme.bg.width = stage.stageWidth; colorScheme.y = stage.stageHeight - colorScheme.height; colorScheme.colorPic.x = stage.stageWidth - 458; for(var i:int = 1; i<=5; i++){ var btn:MovieClip = MovieClip(colorScheme.colorPic.getChildByName("btn"+i)); btn.index = i; btn.buttonMode = true; if(i != activeColor){ btn.gotoAndStop(1); } //adding event listeners to color scheme btns btn.addEventListener(MouseEvent.MOUSE_OVER, btnOver); btn.addEventListener(MouseEvent.MOUSE_OUT, btnOut); btn.addEventListener(MouseEvent.CLICK, btnClick); } addChild(colorScheme); } //action button Over private function btnOver(e:MouseEvent):void{ if(e.target.parent.index != activeColor){ e.target.parent.gotoAndPlay("over"); } } //action button Out private function btnOut(e:MouseEvent):void{ if(e.target.parent.index != activeColor){ e.target.parent.gotoAndPlay("out"); } } //action button Click private function btnClick(e:MouseEvent):void{ if(e.target.parent.index != activeColor){ var btn:MovieClip = MovieClip(colorScheme.colorPic.getChildByName("btn"+activeColor)); btn.gotoAndPlay("out"); activeColor = e.target.parent.index; //change the color scheme switch(activeColor){ case 1: TweenLite.to(bg.bg, 1, {tint:0x01003e }); TweenLite.to(title1, 1, {tint:0xfff4ab }); TweenLite.to(title2, 1, {tint:0xffffff}); break; case 2: TweenLite.to(bg.bg, 1, {tint:0x2b0146 }); TweenLite.to(title1, 1, {tint:0xe0b1ff }); TweenLite.to(title2, 1, {tint:0xc979b5 }); break; case 3: TweenLite.to(bg.bg, 1, {tint:0x5a001d }); TweenLite.to(title1, 1, {tint:0xffde6c }); TweenLite.to(title2, 1, {tint:0xd64c78 }); break; case 4: TweenLite.to(bg.bg, 1, {tint:0x1f4101 }); TweenLite.to(title1, 1, {tint:0xffffff }); TweenLite.to(title2, 1, {tint:0xbcce3a }); break; case 5: TweenLite.to(bg.bg, 1, {tint:0x613e00 }); TweenLite.to(title1, 1, {tint:0xfed943 }); TweenLite.to(title2, 1, {tint:0xded0a5}); break; } } } //init Title1 private function initTitle1():void{ title1 = new Title1(); title1.name = "title1"; title1._txt.autoSize = TextFieldAutoSize.CENTER; title1._txt.htmlText = globalXml.title1[0]; MyFunc.colorElements(globalXml.title1[0].@color, title1); title1.x = Math.round((stage.stageWidth - title1.width)/2); title1.y = year.y + 200 + 48; title1.visible = false; addChild(title1); TweenMax.to(title1, 0.1, {blurFilter:{blurX:28, blurY:10, quality:5}, alpha:0.5, onComplete: function(){ title1.visible = true; TweenMax.to(title1, 1.2, {alpha:1, blurFilter:{blurX:0, blurY:0, quality:5}}); }}); } //init Title2 private function initTitle2():void{ title2 = new Title2(); title2.name = "title2"; title2._txt.autoSize = TextFieldAutoSize.CENTER; title2._txt.htmlText = globalXml.title2[0]; MyFunc.colorElements(globalXml.title2[0].@color, title2); title2.x = Math.round((stage.stageWidth - title2.width)/2); title2.y = year.y + 200 + 142; title2.visible = false; addChild(title2); TweenMax.to(title2, 0.1, { delay:1.2, blurFilter:{blurX:20, blurY:10, quality:5}, alpha:0.5, onComplete: function(){ title2.visible = true; TweenMax.to(title2, 1.2, {alpha:1, blurFilter:{blurX:0, blurY:0, quality:5}}); }}); } //init 2011 private function initYear():void{ year = new Year(); year.name = "year"; year.x = Math.round((stage.stageWidth - year.width)/2)-14; year.y = Math.round((thisHeight - year.height)/9*3); addChild(year); } //init Bg private function initBg():void{ bg = new Bg(); bg.name = "bg"; bg.bg.width = stage.stageWidth; bg.bg.height = thisHeight; MyFunc.colorElements(globalXml.bg.@color, bg.bg); bg.sh1.x = Math.round((stage.stageWidth - bg.sh1.width)/2)+100; bg.sh2.x = Math.round((stage.stageWidth - bg.sh2.width)/2)+100; bg.sh1.y = Math.round((thisHeight - bg.sh1.height)/2)-142; bg.sh2.y = Math.round((thisHeight - bg.sh2.height)/2)-142; bg.year.x = Math.round((stage.stageWidth - bg.year.width)/2)-14; bg.year.y = Math.round((thisHeight - bg.year.height)/9*3); //if(bg.stripes.width < stage.stageWidth){ var nX:int = Math.ceil(stage.stageWidth/bg.stripes.width); var nY:int = Math.ceil(thisHeight/bg.stripes.height); for(var i:int = 0; i