Advertisement
Guest User

AS#

a guest
Jul 12th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import com.greensock.TweenLite;
  4.     import com.greensock.easing.*;
  5.     import com.greensock.plugins.*;
  6.    
  7.     import flash.display.Loader;
  8.     import flash.display.MovieClip;
  9.     import flash.events.Event;
  10.     import flash.events.IEventDispatcher;
  11.     import flash.net.URLLoader;
  12.     import flash.net.URLRequest;
  13.     import flash.net.URLVariables;
  14.     import flash.text.AntiAliasType;
  15.     import flash.text.TextField;
  16.     import flash.text.TextFieldAutoSize;
  17.     import flash.text.TextFormat;
  18.    
  19.     public class DatabaseAccess extends MovieClip
  20.     {
  21.         [Embed(source="assets/fonts/trebuc.ttf", fontFamily="Trebuchet", fontWeight="normal", mimeType='application/x-font', embedAsCFF='false')]
  22.         private var TrebuchetMSFont:Class;
  23.        
  24.         [Embed(source="assets/fonts/times.ttf", fontFamily="TimesNewRoman", fontWeight="normal", mimeType='application/x-font', embedAsCFF='false')]
  25.         private var TimesNewRomanFont:Class;
  26.        
  27.         //Project Visual Content
  28.         var store_txt:TextField;
  29.         var productName_txt:TextField;
  30.         var price_txt:TextField;
  31.         var product_mc:MovieClip;
  32.        
  33.         //Helpers
  34.         var imageLoader:Loader;
  35.         var prodX:Number;       //product x-coord and y-coord
  36.         var prodY:Number;
  37.        
  38.         public function DatabaseAccess()
  39.         {          
  40.             TweenPlugin.activate([TintPlugin]);
  41.            
  42.            
  43.             var req:URLRequest = new URLRequest("http://blackbox/ajax/dbaccess.aspx");
  44.             var vars:URLVariables = new URLVariables();
  45.             vars.action = "getImg"
  46.             vars.groupIDs = "450997, 300042";
  47.             req.data = vars;
  48.             var imgLdr:URLLoader = new URLLoader();
  49.             imageLoader = new Loader();
  50.             var product_xml:XML;
  51.             configureListeners(imgLdr);
  52.            
  53.             //Define all the visible components!
  54.             //========================
  55.             //Store Label:
  56.             //Custom font embedded in the flash project. REQUIRED TO BE ABLE TO ROTATE TEXTFIELDS!
  57.             var myStoreFont:String = new TrebuchetMSFont();
  58.             //var myStoreFont:TrebuchetMSFont = new TrebuchetMSFont();
  59.             //The font formatter
  60.             var myStoreFormat:TextFormat = new TextFormat();
  61.             myStoreFormat.font = myStoreFont;
  62.             trace(myStoreFormat.font);
  63.             myStoreFormat.size = 60;
  64.             //The store label
  65.             store_txt = new TextField();
  66.             store_txt.autoSize = TextFieldAutoSize.LEFT;
  67.             store_txt.defaultTextFormat = myStoreFormat;
  68.             store_txt.embedFonts = true;
  69.             store_txt.antiAliasType = AntiAliasType.ADVANCED;
  70.             store_txt.text = "HomeFurnitureShowroom";
  71.             store_txt.rotation = 270;
  72.             store_txt.alpha = 0;
  73.             addChild(store_txt);
  74.             //================
  75.             //Product Name Label:
  76.             //var myGenericFont:String = new TimesNewRomanFont();
  77.             ////var myGenericFont:TimesNewRomanFont = new TimesNewRomanFont();
  78.             ////The font formatter
  79.             //var myProductNamePriceFormat:TextFormat = new TextFormat();
  80.             //myProductNamePriceFormat.font = myGenericFont;
  81.             //myProductNamePriceFormat.size = 30;
  82.             //The product name label
  83.             productName_txt = new TextField();
  84.             productName_txt.autoSize = TextFieldAutoSize.LEFT;
  85.             //productName_txt.defaultTextFormat = myProductNamePriceFormat;
  86.             //productName_txt.embedFonts = true;
  87.             //productName_txt.antiAliasType = AntiAliasType.ADVANCED;
  88.             productName_txt.x = 0;
  89.             productName_txt.y = 0;
  90.             productName_txt.text = "";
  91.             addChild(productName_txt);
  92.             //================
  93.             //Product Price Label:
  94.             price_txt = new TextField();
  95.             price_txt.autoSize = TextFieldAutoSize.LEFT;
  96.             //price_txt.defaultTextFormat = myProductNamePriceFormat;
  97.             //price_txt.embedFonts = true;
  98.             price_txt.antiAliasType = AntiAliasType.ADVANCED;
  99.             price_txt.x = 75;
  100.             price_txt.y = 100;
  101.             price_txt.text = "";
  102.             addChild(price_txt);
  103.             //================
  104.             //Product Image MovieClip:
  105.             product_mc = new MovieClip()
  106.             addChildAt(product_mc, 0);
  107.            
  108.             imgLdr.load(req);
  109.            
  110.             stop();
  111.         }
  112.        
  113.         function configureListeners(dispatcher:IEventDispatcher):void
  114.         {
  115.             dispatcher.addEventListener(Event.COMPLETE, xmlLoad);
  116.         }
  117.        
  118.         function xmlLoad(event:Event):void
  119.         {
  120.             var productList:XMLList = new XML(event.target.data).product;
  121.            
  122.             var i:Number;
  123.             for (i = 0; i < productList.length(); i++)
  124.             {
  125.                 trace(productList.imgurl.text()[i]);
  126.             }
  127.            
  128.             //Set Product Name
  129.             productName_txt.text = productList.name.text()[0];
  130.             productName_txt.alpha = 0;
  131.            
  132.             //Set Product Price
  133.             price_txt.text = productList.price.text()[0];
  134.             price_txt.alpha = 0;
  135.            
  136.             //Load and Set Product Image
  137.             var image:URLRequest = new URLRequest(productList.imgurl.text()[0]);
  138.             imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, prodImgLoad);
  139.             try
  140.             {
  141.                 imageLoader.load(image);
  142.             }
  143.             catch(e:SecurityError)
  144.             {
  145.                 //trace(e);
  146.             }
  147.             product_mc.addChild (imageLoader);
  148.             product_mc.x = 0;
  149.             product_mc.y = 0;
  150.         }
  151.        
  152.         function prodImgLoad(e:Event):void
  153.         {
  154.             prodX = imageLoader.getChildAt(0).width;
  155.             prodY = imageLoader.getChildAt(0).height;
  156.            
  157.             store_txt.rotation = 270;
  158.             //trace(stage.stageWidth + "," + stage.stageHeight + " - " + store_txt.width + "," + store_txt.height + " - " + (stage.stageWidth - store_txt.width) + "," + stage.stageHeight);
  159.             store_txt.x = stage.stageWidth - store_txt.width;
  160.             store_txt.y = stage.stageHeight - 100;
  161.            
  162.             animateVideo();
  163.         }
  164.        
  165.         function animateVideo():void
  166.         {
  167.             //NOTE: Overlaping where one tween ends and another begins helps smooth out the transition between tweens.
  168.             //Otherwise the tweens tend to slow down near the end
  169.            
  170.             //Product
  171.             var origTint = product_mc.tint;
  172.             product_mc.registration
  173.             TweenLite.to(product_mc, .5, {tint:0x000001, delay:.2});                //fade out
  174.             TweenLite.to(product_mc, 0, {tint:origTint, alpha:0, scaleX:1.2, scaleY:1.2, delay:.7, overwrite:false});   //insta-fade in
  175.             TweenLite.to(product_mc, 2, {alpha:1, scaleX:1, scaleY:1, delay:.7, overwrite:false});  //fade in and zoom out
  176.             TweenLite.to(product_mc, 5, {scaleX:.8, scaleY:.8, delay:1.7, overwrite:false});        //continue zooming out
  177.            
  178.             //Static Store name
  179.             TweenLite.to(store_txt, .5, {alpha:1, y:stage.stageHeight - 80, overwrite:false});
  180.             TweenLite.to(store_txt, 6.5, {y:stage.stageHeight + 120, overwrite:false});
  181.            
  182.             //Product name
  183.             TweenLite.to(productName_txt, 1, {alpha:1, delay:6.5});
  184.            
  185.             //Product price
  186.             TweenLite.to(price_txt, 1, {alpha:1, delay:6.5});
  187.         }
  188.     }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement