/**
* Makes a bitmap copy of an image clip and
* rewrites it with the same name, depth, position.
*
* @param target The movie clip to replace.
* @param transparent Specifies whether the bitmap image supports per-pixel transparency.
* @param fillColor A 32-bit ARGB color value that you use to fill the bitmap image area.
*/
function replaceByBitmap(target:MovieClip, transparent:Boolean, fillColor:Number):Void {
import flash.display.BitmapData;
var ox:Number = target._x;
var oy:Number = target._y;
if(transparent && fillColor){
var bm:BitmapData = new BitmapData(target._width, target._height, true, 0x00FFFFFF);
}else{
var bm:BitmapData = new BitmapData(target._width, target._height);
}
bm.draw(target);
var copy_mc:MovieClip = target._parent.createEmptyMovieClip(target._name, target.getDepth());
copy_mc.attachBitmap(bm, 0, "never", true);
copy_mc._x = ox;
copy_mc._y = oy;
}
class com.orazal.tools.PositionUtils {
/**
* Returns x and y positions for a grid
*
* @param amount The total amount of items
* @param limit The row or column limit before line break
* @param width The item's with
* @param height The item's height
* @param direction Horizontal or Vertical
* @returns An array with a position object with the x and y properties
*/
public static function getGridPositions(amount:Number, limit:Number,
width:Number, height:Number,
direction:String):Array {
// Set direction as horizontal if none is found
if (!direction) {
direction = "horizontal";
}
var pos_ar:Array = new Array();
for (var i:Number = 0; i<20; i++) {
switch (direction) {
case "horizontal" :
var column:Number = i%limit;
var row:Number = Math.floor(i/limit);
break;
case "vertical" :
var row:Number = i%limit;
var column:Number = Math.floor(i/limit);
break;
}
var xPos = column*width;
var yPos = row*height;
pos_ar.push({x:xPos, y:yPos});
}
return pos_ar;
}
/**
* Calculates a clip's final size and position from a provided registration point
*
*@param clip The movieclip to zoom
*@param percent The amount to zoom
*@param xOffset The percentage (in decimals) to offset horizontally from clip's center
*@param yOffset The percentage (in decimals) to offset vertically from clip's center
*@returns An object with the final width, height, x and y positions
*/
public static function zoomFromPoint(clip:MovieClip, percent:Number,
xOffset:Number, yOffset:Number):Object {
// Convert zoom percent to decimals
percent /= 100;
// Get original width and height
var originalW = clip._width/(clip._xscale/100);
var originalH = clip._height/(clip._yscale/100);
// Center register position if not provided
if (!xOffset) {
var xOffset:Number = 0.5;
}
if (!yOffset) {
var yOffset:Number = 0.5;
}
// Determine x and y positions
var centerX = clip._x+(clip._width*xOffset);
var centerY = clip._y+(clip._height*yOffset);
// Determine final positions
var final:Object = new Object();
final.width = originalW*percent;
final.height = originalH*percent;
final.x = centerX-(final.width*xOffset);
final.y = centerY-(final.height*yOffset);
return final;
}
}
/*
* Checks a clip's position and size and repositions inside an area
*
*@param clip Movieclip to reposition
*@param area An object indication the area that the clip should be constrained to
*@param reposition Boolean indicating if movieclip's position should be modified
*@param hSpacing Horizontal margin from the border
*@param vSpacing Vertical margin from the border
*@returns An object with the x and y values that are inside the area
*/
function constrainToArea(clip:MovieClip, area:Object, reposition:Boolean, hSpacing:Number, vSpacing:Number):Array {
if (!hSpacing) {
var hSpacing:Number = 0;
}
if (!vSpacing) {
var vSpacing:Number = 0;
}
var clipPoint:Object = new Object();
clipPoint.x = clip._x;
clipPoint.y = clip._y;
clip._parent.localToGlobal(clipPoint);
// Return same position
var newX = clip._x;
var newY = clip._y;
// Reposition on x
var overX = area.width-(clipPoint.x+clip._width);
if (overX<0) {
newX -= Math.abs(overX)+hSpacing;
}
if (clipPoint.x<0) {
newX += Math.abs(clipPoint.x)+hSpacing;
}
// Reposition on y
var overY = area.height-(clipPoint.y+clip._height);
if (overY<0) {
newY -= Math.abs(overY)+vSpacing;
}
if (clipPoint.y<0) {
newY += Math.abs(clipPoint.y)+vSpacing;
}
if (reposition) {
clip._x = newX;
clip._y = newY;
}
return {x:newX, y:newY};
}
/*
Between the time an instance is created and destroyed, a number of things can happen. To simplify how things work, they are divided into three sections: startup, midlife, and shutdown.
Each application object is a singleton object. Each instance gets it's own application object which is an instance of the Application class.
These are all the standard event handler method of the application object
*/
/***************************
Startup
***************************/
application.onAppStart = function ( ) {
//A. onAppStart is where to Initialize counters, variables, id's, etc
trace( "onAppStart> " + application.name + " is starting at " + new Date() );
//B. You can set up a Server-side shared object to synchronize clients
this.so = SharedObject.get(application.name + ".com", true);
//C. This is the proper way to set default variables. It allows for expansion
if(this.so.getProperty("t" == undefined)){}
if(this.so.getProperty("foo" == undefined)){}
//Always assign unique ID's on the Server-Side because it's single threaded
this.nextUserId = 0;
};
application.onStatus = function (info) {
trace("onStatus> info.level: " + info.level + ", info.code: " + info.code);
trace("onStatus> info.description: " + info.description);
trace("onStatus> info.details: " + info.details);
};
application.onConnect = function (p_client, userName, password) {
//A. Assign a uniqueID for any user who logs in
//p_client.userId = this.nextUserId++;
//B. Decide is a client needs a userName
p_client.userName = userName;
//C. Decide is you want to give a client user read/write access
//p_client.writeAccess = "/public";
//p_client.readAccess = "/";
//D. Inform the user that they have made a success connection
application.acceptConnection(p_client);
trace("onConnect> client.ip: " + p_client.ip);
trace("onConnect> client.agent: " + p_client.agent);
trace("onConnect> client.referrer: " + p_client.referrer);
trace("onConnect> client.protocol: " + p_client.protocol);
};
application.onDisconnect = function (p_client) {
//A. Clear any session variables that may pertain to a client user (SharedObject variables)
trace("onDisconnect> client.userName: " + p_client.userName)
trace("onDisconnect> disconnecting at: " + new Date( ));
};
/***************************
Shutdown
***************************/
application.onAppStop = function (info) {
//A. For when the app stops
trace("onAppStop> application.name: " + application.name);
trace("onAppStop> stopping at " + new Date( ));
trace("onAppStop> info.level: " + info.level);
trace("onAppStop> info.code: " + info.code);
trace("onAppStop> info.description: " + info.description);
};
/***************************
MidLife
***************************/
/*
Below are methods that any client can call. You are also able to write such methods within onConnect like:
///////////////////////////////////////////////////
application.onConnect = function(p_client){
p_client.changeText = function(p_client){
//Do Something
}
}
///////////////////////////////////////////////////
The reason you may not want to do this is because every time a user connects, this function will be placed into memory. Therefore if many users connect, you could begin to fing issues with memory allocation so it's much more efficient to use the psuedo Javascript Class called prototype.
*/
Client.prototype.changeText = function(p_client){
}
Client.prototype.getStreamLength = function(p_streamName) {
trace("Stream.length: " + p_streamName + ", " + Stream.length(p_streamName));
return Stream.length(p_streamName);
}
//A. Create CSS as a String
var css:String = ".headline {color: #FFCCCC; font-size: 18px}, p {color: #666666; font-size: 14px; font-weight: bold;}";
//B. Create a new Style Sheet & Parse the CSS
var ss = new TextField.StyleSheet();
ss.parseCSS(css);
//C. Create Some Strings
var headline:String = "<span class='headline'>Header 1</span><br>";
var p:String = "<p>lorem ipsum.....</p>";
//D. Create a Dynamic Text Field
var text_txt:TextField = this.createTextField("text_txt", this.getNextHighestDepth(), 0, 0, 100, 50);
text_txt.multiline = true;
text_txt.wordWrap = true;
text_txt.html = true;
text_txt.styleSheet = ss;
//E. Bind
text_txt.htmlText = headline + p;
// ************************************************** //
// Author: ImHugo
// URL: http://www.imhugo.com
// ************************************************** //
// Vars
var arrayToRandom:Array = new Array();
var qRequired:Number = 5;
// Inserts Numbers in Array
for(var i:Number = 1; i<=qRequired; i++)
{
arrayToRandom.push( i );
}
// Outputs numbers non-repeated
for(var k:Number = 1; k<=qRequired; k++)
{
// Search for value inside the Array in a random position
var randomPos:Number = Math.floor( Math.random() * arrayToRandom.length );
// Selects value and removes it from Array
var valueFromArray = arrayToRandom.splice(randomPos, 1);
// Converts value in number
var numberRand = parseInt(valueFromArray);
trace(numberRand);
}