Instantly share code, notes, and snippets.
Last active
September 2, 2016 20:11
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save astein/e3e03d8750993fd7facc to your computer and use it in GitHub Desktop.
Whitewave - ID Ready to Drink, Q2/Q3, '15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.socialvibe.modules.logic | |
{ | |
import com.adobe.serialization.json.JSONDecoder; | |
import com.greensock.TweenLite; | |
import com.greensock.easing.Elastic; | |
import com.greensock.easing.Expo; | |
import com.greensock.easing.Linear; | |
import com.greensock.easing.Quad; | |
import com.greensock.easing.Strong; | |
import com.socialvibe.core.ui.controls.SVButton; | |
import com.socialvibe.core.ui.controls.SVImage; | |
import com.socialvibe.core.ui.controls.SVSWFLoader; | |
import com.socialvibe.core.ui.controls.SVText; | |
import com.socialvibe.core.utils.SVEvent; | |
import com.socialvibe.engagement.EngagementParameters; | |
import com.socialvibe.engagement.EngagementTracking; | |
import com.socialvibe.engagement.EngagementUtils; | |
import com.socialvibe.engagement.controller.CustomLogicControllerBase; | |
import com.socialvibe.engagement.view.controls.video.SVVideo; | |
import com.socialvibe.engagement.view.controls.video.VideoPlayerBase; | |
import com.socialvibe.tools.builder.model.BuilderEngagementMaterial; | |
import com.socialvibe.tools.builder.view.panels.EngagementStep; | |
import flash.display.Bitmap; | |
import flash.display.BitmapData; | |
import flash.display.DisplayObject; | |
import flash.display.Loader; | |
import flash.display.LoaderInfo; | |
import flash.display.Sprite; | |
import flash.events.DataEvent; | |
import flash.events.Event; | |
import flash.events.MouseEvent; | |
import flash.events.TimerEvent; | |
import flash.external.ExternalInterface; | |
import flash.system.Security; | |
import flash.utils.setTimeout; | |
public class QuickLogic extends CustomLogicControllerBase | |
{ | |
private var _fbButton:SVButton; | |
private var _twButton:SVButton; | |
private var _pinButton:SVButton; | |
private var _swf:SVSWFLoader; | |
private var _dialog:SVImage; | |
private var _overlay:SVImage; | |
private var _loading:SVText; | |
private var _shareBitmap:Bitmap; | |
private var _uploader:ImageUploader; | |
private var _shareImgURL:String; | |
private var _foregroundShareImg:SVImage; | |
public function QuickLogic() { | |
Security.allowDomain("*"); | |
} | |
override public function getControllerName():String { return 'id_img_share_logic'; } | |
override public function init():void | |
{ | |
} | |
override public function applyLogic(steps:Array):void | |
{ | |
_fbButton = _material.getControl('misc_button 4') as SVButton; | |
_pinButton = _material.getControl('misc_button 5') as SVButton; | |
_twButton = _material.getControl('misc_button 9') as SVButton; | |
_dialog = _material.getControl('image 2') as SVImage; | |
_overlay = _material.getControl('image 6') as SVImage; | |
_swf = _material.getControl('swf 1') as SVSWFLoader; | |
_fbButton.visible = _pinButton.visible = _twButton.visible = _dialog.visible = _overlay.visible = false; | |
_material.getControl('misc_button 3').visible = false; | |
_fbButton.addEventListener(MouseEvent.CLICK, onFBShare); | |
_pinButton.addEventListener(MouseEvent.CLICK, onPinShare); | |
_twButton.addEventListener(MouseEvent.CLICK, onTwShare); | |
_overlay.addEventListener(MouseEvent.CLICK, onOverlayClick); | |
_foregroundShareImg = new SVImage('//media.truex.com/m/activties/blue_buffalo/InternationalDelight_share.png'); | |
_api.addJSListener('STEP_CHANGE', onStepChange); | |
_material.base.addEventListener('start_share', onStartShare); | |
} | |
private function onOverlayClick(e:Event):void | |
{ | |
_fbButton.visible = _pinButton.visible = _twButton.visible = _dialog.visible = _overlay.visible = false; | |
} | |
private function onStartShare(e:Event):void | |
{ | |
//ExternalInterface.call('console.log', 'start_share'); | |
_dialog.visible = true; | |
_overlay.visible = true; | |
TweenLite.from(_dialog, 0.5, {alpha:0}); | |
TweenLite.from(_overlay, 0.5, {alpha:0}); | |
if (_shareImgURL) { | |
showShare(); | |
} else { | |
_loading = new SVText('Loading...', 36, 25); | |
_dialog.addChild(_loading); | |
var b:BitmapData = new BitmapData(750, 500, false); | |
b.draw(_swf); | |
var swfBitmap:Bitmap = new Bitmap(b); | |
var composite:Sprite = new Sprite(); | |
swfBitmap.y = 120; | |
composite.addChild(swfBitmap); | |
composite.addChild(_foregroundShareImg); | |
b = new BitmapData(750, 620, false); | |
b.draw(composite); | |
_shareBitmap = new Bitmap(b); | |
_uploader = new ImageUploader(_shareBitmap); | |
_uploader.addEventListener(ImageUploader.ASSET_UPLOAD_COMPLETE, onUploaded); | |
} | |
} | |
private function onStepChange(e:Object):void | |
{ | |
var currentStep:int = _api.getCurrentStep(); | |
if (currentStep == 5) { | |
setTimeout(function():void { | |
_material.getControl('misc_button 3').visible = true; | |
TweenLite.from(_material.getControl('misc_button 3'), 1, {alpha:0}); | |
}, 4200); | |
} else if (currentStep == 6) { | |
_material.getControl('misc_button 3').visible = false; | |
} | |
} | |
private function onUploaded(e:SVEvent):void | |
{ | |
_shareImgURL = String(e.data); | |
//ExternalInterface.call('console.log', _shareImgURL); | |
showShare(); | |
} | |
private function showShare():void | |
{ | |
if (!_overlay.visible) | |
return; | |
_loading.visible = false; | |
_fbButton.visible = _pinButton.visible = _twButton.visible = _dialog.visible = true; | |
} | |
private function onTwShare(e:Event):void | |
{ | |
shareToTwitter('My coffee shop name today. Find yours at www.InternationalDelight.com/IDelightIn10', _shareImgURL); | |
_fbButton.visible = _pinButton.visible = _twButton.visible = _dialog.visible = _overlay.visible = false; | |
} | |
private function onFBShare(e:Event):void | |
{ | |
shareToFacebook('', 'Check out my coffee shop name for today.', '', 'Why wait at the coffee shop when delight is waiting in your fridge? Check out InternationalDelight at www.InternationalDelight.com/IDelightIn10', _shareImgURL); | |
_fbButton.visible = _pinButton.visible = _twButton.visible = _dialog.visible = _overlay.visible = false; | |
} | |
private function onPinShare(e:Event):void | |
{ | |
shareToPinterest('', 'Check out my coffee shop name for today. Why wait at the coffee shop when delight is waiting in your fridge? Check out InternationalDelight at www.InternationalDelight.com/IDelightIn10', _shareImgURL); | |
_fbButton.visible = _pinButton.visible = _twButton.visible = _dialog.visible = _overlay.visible = false; | |
} | |
public function js(module:String, method:String, args:Array = null):* | |
{ | |
if(args == null) | |
args = []; | |
args.unshift('TXM.' + module + '.' + method); | |
return ExternalInterface.call.apply(null, args); | |
} | |
public function shareToFacebook(url:String = null, title:String = null, caption:String = null, description:String = null, img_url:String = ''):void | |
{ | |
js('utils', 'shareToFacebook', [url, title, caption, description, img_url]); | |
} | |
public function shareToPinterest(url:String = null, description:String = null, img_url:String = null):void | |
{ | |
js('utils', 'shareToPinterest', [url, img_url, description]); | |
} | |
public function shareToTwitter(tweet:String = null, url:String = null):void | |
{ | |
js('utils', 'shareToTwitter', [tweet, url]); | |
} | |
override public function onStepStart(step:EngagementStep):void | |
{ | |
} | |
override public function onStepEnd(step:EngagementStep):void | |
{ | |
} | |
} | |
} | |
import com.adobe.images.JPGEncoder; | |
import com.adobe.serialization.json.JSONDecoder; | |
import com.socialvibe.core.ui.SVSquareLoader; | |
import com.socialvibe.core.utils.SVEvent; | |
import com.socialvibe.engagement.EngagementAPI; | |
import flash.display.Bitmap; | |
import flash.events.Event; | |
import flash.events.EventDispatcher; | |
import ru.inspirit.MultipartURLLoader; | |
internal class ImageUploader extends EventDispatcher | |
{ | |
public static const ASSET_UPLOAD_COMPLETE:String = 'assetUploadComplete'; | |
protected var _loader:MultipartURLLoader; | |
protected var _loadingGraphic:SVSquareLoader; | |
protected var _name:String; | |
protected var _assetURL:String; | |
protected var _assetID:Number; | |
protected var _assetName:String; | |
public function ImageUploader(image:Bitmap ):void | |
{ | |
var location:String; | |
_loader = new MultipartURLLoader(); | |
_loader.addEventListener(Event.COMPLETE, onFileUploaded); | |
_loader.addVariable('commit', 'Create'); | |
_loader.addFile( (new JPGEncoder(80).encode( image.bitmapData ) ), 'barista_name', "photo", 'image/jpg'); | |
_loader.load( 'https://serve.truex.com/engagements/create_photo.xml' ); | |
} | |
protected function onFileUploaded(e:Event = null):void | |
{ | |
_assetURL = _loader.loader.data; | |
var _api:EngagementAPI = EngagementAPI.getInstance(); | |
_api.trackUpload( _assetURL, true ) | |
dispatchEvent( new SVEvent( ASSET_UPLOAD_COMPLETE, _assetURL, true, true ) ); | |
} | |
protected function jsonDecode(json:String):Object | |
{ | |
if (json) | |
{ | |
try { | |
return new JSONDecoder(json).getValue(); | |
} catch (e:Error) { } | |
} | |
return null; | |
} | |
public function get assetURL():String { return _assetURL; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment