Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import com.greensock.TweenLite;
- import com.greensock.easing.*;
- import com.greensock.plugins.*;
- import flash.display.Loader;
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.IEventDispatcher;
- import flash.net.URLLoader;
- import flash.net.URLRequest;
- import flash.net.URLVariables;
- import flash.text.AntiAliasType;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
- public class DatabaseAccess extends MovieClip
- {
- [Embed(source="assets/fonts/trebuc.ttf", fontFamily="Trebuchet", fontWeight="normal", mimeType='application/x-font', embedAsCFF='false')]
- private var TrebuchetMSFont:Class;
- [Embed(source="assets/fonts/times.ttf", fontFamily="TimesNewRoman", fontWeight="normal", mimeType='application/x-font', embedAsCFF='false')]
- private var TimesNewRomanFont:Class;
- //Project Visual Content
- var store_txt:TextField;
- var productName_txt:TextField;
- var price_txt:TextField;
- var product_mc:MovieClip;
- //Helpers
- var imageLoader:Loader;
- var prodX:Number; //product x-coord and y-coord
- var prodY:Number;
- public function DatabaseAccess()
- {
- TweenPlugin.activate([TintPlugin]);
- var req:URLRequest = new URLRequest("http://blackbox/ajax/dbaccess.aspx");
- var vars:URLVariables = new URLVariables();
- vars.action = "getImg"
- vars.groupIDs = "450997, 300042";
- req.data = vars;
- var imgLdr:URLLoader = new URLLoader();
- imageLoader = new Loader();
- var product_xml:XML;
- configureListeners(imgLdr);
- //Define all the visible components!
- //========================
- //Store Label:
- //Custom font embedded in the flash project. REQUIRED TO BE ABLE TO ROTATE TEXTFIELDS!
- var myStoreFont:String = new TrebuchetMSFont();
- //var myStoreFont:TrebuchetMSFont = new TrebuchetMSFont();
- //The font formatter
- var myStoreFormat:TextFormat = new TextFormat();
- myStoreFormat.font = myStoreFont;
- trace(myStoreFormat.font);
- myStoreFormat.size = 60;
- //The store label
- store_txt = new TextField();
- store_txt.autoSize = TextFieldAutoSize.LEFT;
- store_txt.defaultTextFormat = myStoreFormat;
- store_txt.embedFonts = true;
- store_txt.antiAliasType = AntiAliasType.ADVANCED;
- store_txt.text = "HomeFurnitureShowroom";
- store_txt.rotation = 270;
- store_txt.alpha = 0;
- addChild(store_txt);
- //================
- //Product Name Label:
- //var myGenericFont:String = new TimesNewRomanFont();
- ////var myGenericFont:TimesNewRomanFont = new TimesNewRomanFont();
- ////The font formatter
- //var myProductNamePriceFormat:TextFormat = new TextFormat();
- //myProductNamePriceFormat.font = myGenericFont;
- //myProductNamePriceFormat.size = 30;
- //The product name label
- productName_txt = new TextField();
- productName_txt.autoSize = TextFieldAutoSize.LEFT;
- //productName_txt.defaultTextFormat = myProductNamePriceFormat;
- //productName_txt.embedFonts = true;
- //productName_txt.antiAliasType = AntiAliasType.ADVANCED;
- productName_txt.x = 0;
- productName_txt.y = 0;
- productName_txt.text = "";
- addChild(productName_txt);
- //================
- //Product Price Label:
- price_txt = new TextField();
- price_txt.autoSize = TextFieldAutoSize.LEFT;
- //price_txt.defaultTextFormat = myProductNamePriceFormat;
- //price_txt.embedFonts = true;
- price_txt.antiAliasType = AntiAliasType.ADVANCED;
- price_txt.x = 75;
- price_txt.y = 100;
- price_txt.text = "";
- addChild(price_txt);
- //================
- //Product Image MovieClip:
- product_mc = new MovieClip()
- addChildAt(product_mc, 0);
- imgLdr.load(req);
- stop();
- }
- function configureListeners(dispatcher:IEventDispatcher):void
- {
- dispatcher.addEventListener(Event.COMPLETE, xmlLoad);
- }
- function xmlLoad(event:Event):void
- {
- var productList:XMLList = new XML(event.target.data).product;
- var i:Number;
- for (i = 0; i < productList.length(); i++)
- {
- trace(productList.imgurl.text()[i]);
- }
- //Set Product Name
- productName_txt.text = productList.name.text()[0];
- productName_txt.alpha = 0;
- //Set Product Price
- price_txt.text = productList.price.text()[0];
- price_txt.alpha = 0;
- //Load and Set Product Image
- var image:URLRequest = new URLRequest(productList.imgurl.text()[0]);
- imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, prodImgLoad);
- try
- {
- imageLoader.load(image);
- }
- catch(e:SecurityError)
- {
- //trace(e);
- }
- product_mc.addChild (imageLoader);
- product_mc.x = 0;
- product_mc.y = 0;
- }
- function prodImgLoad(e:Event):void
- {
- prodX = imageLoader.getChildAt(0).width;
- prodY = imageLoader.getChildAt(0).height;
- store_txt.rotation = 270;
- //trace(stage.stageWidth + "," + stage.stageHeight + " - " + store_txt.width + "," + store_txt.height + " - " + (stage.stageWidth - store_txt.width) + "," + stage.stageHeight);
- store_txt.x = stage.stageWidth - store_txt.width;
- store_txt.y = stage.stageHeight - 100;
- animateVideo();
- }
- function animateVideo():void
- {
- //NOTE: Overlaping where one tween ends and another begins helps smooth out the transition between tweens.
- //Otherwise the tweens tend to slow down near the end
- //Product
- var origTint = product_mc.tint;
- product_mc.registration
- TweenLite.to(product_mc, .5, {tint:0x000001, delay:.2}); //fade out
- TweenLite.to(product_mc, 0, {tint:origTint, alpha:0, scaleX:1.2, scaleY:1.2, delay:.7, overwrite:false}); //insta-fade in
- TweenLite.to(product_mc, 2, {alpha:1, scaleX:1, scaleY:1, delay:.7, overwrite:false}); //fade in and zoom out
- TweenLite.to(product_mc, 5, {scaleX:.8, scaleY:.8, delay:1.7, overwrite:false}); //continue zooming out
- //Static Store name
- TweenLite.to(store_txt, .5, {alpha:1, y:stage.stageHeight - 80, overwrite:false});
- TweenLite.to(store_txt, 6.5, {y:stage.stageHeight + 120, overwrite:false});
- //Product name
- TweenLite.to(productName_txt, 1, {alpha:1, delay:6.5});
- //Product price
- TweenLite.to(price_txt, 1, {alpha:1, delay:6.5});
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement