Skip to content

Instantly share code, notes, and snippets.

View mattlundstrom's full-sized avatar

Matt Lundstrom mattlundstrom

View GitHub Profile
@mattlundstrom
mattlundstrom / gist:8c45ac52b71791db5505
Last active August 29, 2015 14:19
Dirty Video Listener 2
// Cuepoints for non flvs
var dirtyVideoListerner:Function = function (_ns:NetStream, _time:Number, _func:Function):void
{
this.addEventListener(Event.ENTER_FRAME, checkTime);
var callingMC:MovieClip = this;
function checkTime():void
{
if (_ns.time > _time)
drawDottedLine( new Point( 0, 0 ), new Point( 500, 100 ), 0x000000, 1, 3, 0, 1 );
function drawDottedLine( _p1:Point, _p2:Point, _color:uint = 0x000000, _thickness:Number = 1, _gap:Number = 10, _offset:Number = 0, _percent:Number = 1 ):void{
var line:MovieClip = new MovieClip();
addChild( line );
var distance:Number = distance( _p1, _p2 );
@mattlundstrom
mattlundstrom / rounding
Last active August 29, 2015 14:01
Rounding
function roundToDecimal( number, decimalPlaces ){
var multiplier = Math.pow( 10, decimalPlaces );
return Math.round( number * multiplier ) / multiplier;
}
function roundNearest( number, nearest ){
return Math.round( number / nearest ) * nearest;
}
@mattlundstrom
mattlundstrom / rAF.js
Created February 18, 2014 22:49 — forked from paulirish/rAF.js
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@mattlundstrom
mattlundstrom / fill fit and center one display object to another
Created December 16, 2013 00:10
fill fit and center one display object to another
function centerTo(_object:DisplayObject, _ref:DisplayObject):void{
if (_object != null){
var _wString:String = "width";
var _hString:String = "height";
if (_ref == stage){
_wString = "stageWidth";
_hString = "stageHeight";
trace("stage");
}
var _refWidth:Number = _ref[_wString];
@mattlundstrom
mattlundstrom / flash trace to console log
Created December 15, 2013 09:23
Flash trace() to console.log
import flash.external.ExternalInterface;
public static function log(msg:String, caller:Object = null):void{
var str:String = "";
if(caller){
str = getQualifiedClassName(caller);
str += ":: ";
}
str += msg;
trace(str);
@mattlundstrom
mattlundstrom / Shortest rotation distance
Created November 27, 2013 20:00
Shortest rotation distance
var rotationdifference:Number = Math.atan2(Math.sin(targetrotation-originalrotation),Math.cos(targetrotation-originalrotation));
@mattlundstrom
mattlundstrom / gist:7162384
Created October 25, 2013 21:52
Center an object with inertia, regardless of it's registration point.
stage.addEventListener(Event.ENTER_FRAME, centerIt);
function centerIt(e:Event){
var boundsRect:Rectangle = mc.getBounds( this );
targetX = ( ( stage.stageWidth - mc.width ) / 2 ) - ( boundsRect.left - mc.x );
targetY = ( ( stage.stageHeight - mc.height ) / 2 ) - ( boundsRect.top - mc.y );
mc.x += ( targetX - mc.x ) / 4;
// Ported from Stefan Gustavson's java implementation
// http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
// Read Stefan's excellent paper for details on how this code works.
//
// Sean McCullough banksean@gmail.com
/**
* You can pass in a random number generator object if you like.
* It is assumed to have a random() method.
*/
@mattlundstrom
mattlundstrom / Click Tag
Last active December 23, 2015 07:49
Standard Banner clickTag code w/ js MSIE popup workaround
myMovieClip.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(e:MouseEvent):void {
var interactiveObject:InteractiveObject = e.target as InteractiveObject;
var li:LoaderInfo = LoaderInfo(interactiveObject.root.loaderInfo);
var url:String = li.parameters.clickTag;
if (url) {
if (ExternalInterface.available) {
var userAgent:String = ExternalInterface.call('function(){ return navigator.userAgent; }');