no commit message
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package ckaction.act {
|
||||
|
||||
import flash.utils.Endian;
|
||||
|
||||
/**
|
||||
* Contains reusable methods for operations pertaining
|
||||
* to int values.
|
||||
*/
|
||||
public class IntUtil {
|
||||
|
||||
/**
|
||||
* Rotates x left n bits
|
||||
*
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0
|
||||
* @tiptext
|
||||
*/
|
||||
public static function rol ( x:int, n:int ):int {
|
||||
return ( x << n ) | ( x >>> ( 32 - n ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates x right n bits
|
||||
*
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0
|
||||
* @tiptext
|
||||
*/
|
||||
public static function ror ( x:int, n:int ):uint {
|
||||
var nn:int = 32 - n;
|
||||
return ( x << nn ) | ( x >>> ( 32 - nn ) );
|
||||
}
|
||||
|
||||
/** String for quick lookup of a hex character based on index */
|
||||
private static var hexChars:String = "0123456789abcdef";
|
||||
|
||||
/**
|
||||
* Outputs the hex value of a int, allowing the developer to specify
|
||||
* the endinaness in the process. Hex output is lowercase.
|
||||
*
|
||||
* @param n The int value to output as hex
|
||||
* @param bigEndian Flag to output the int as big or little endian
|
||||
* @return A string of length 8 corresponding to the
|
||||
* hex representation of n ( minus the leading "0x" )
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0
|
||||
* @tiptext
|
||||
*/
|
||||
public static function toHex( n:int, bigEndian:Boolean = false ):String {
|
||||
var s:String = "";
|
||||
|
||||
if ( bigEndian ) {
|
||||
for ( var i:int = 0; i < 4; i++ ) {
|
||||
s += hexChars.charAt( ( n >> ( ( 3 - i ) * 8 + 4 ) ) & 0xF )
|
||||
+ hexChars.charAt( ( n >> ( ( 3 - i ) * 8 ) ) & 0xF );
|
||||
}
|
||||
} else {
|
||||
for ( var x:int = 0; x < 4; x++ ) {
|
||||
s += hexChars.charAt( ( n >> ( x * 8 + 4 ) ) & 0xF )
|
||||
+ hexChars.charAt( ( n >> ( x * 8 ) ) & 0xF );
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
Adobe Systems Incorporated(r) Source Code License Agreement
|
||||
Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
|
||||
|
||||
Please read this Source Code License Agreement carefully before using
|
||||
the source code.
|
||||
|
||||
Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
|
||||
no-charge, royalty-free, irrevocable copyright license, to reproduce,
|
||||
prepare derivative works of, publicly display, publicly perform, and
|
||||
distribute this source code and such derivative works in source or
|
||||
object code form without any attribution requirements.
|
||||
|
||||
The name "Adobe Systems Incorporated" must not be used to endorse or promote products
|
||||
derived from the source code without prior written permission.
|
||||
|
||||
You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
|
||||
against any loss, damage, claims or lawsuits, including attorney's
|
||||
fees that arise or result from your use or distribution of the source
|
||||
code.
|
||||
|
||||
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
|
||||
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
|
||||
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
|
||||
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package ckaction.act {
|
||||
|
||||
import ckaction.act.IntUtil;
|
||||
import flash.utils.ByteArray;
|
||||
/**
|
||||
* The MD5 Message-Digest Algorithm
|
||||
*
|
||||
* Implementation based on algorithm description at
|
||||
* http://www.faqs.org/rfcs/rfc1321.html
|
||||
*/
|
||||
public class MD5 {
|
||||
|
||||
/**
|
||||
* Performs the MD5 hash algorithm on a string.
|
||||
*
|
||||
* @param s The string to hash
|
||||
* @return A string containing the hash value of s
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 8.5
|
||||
* @tiptext
|
||||
*/
|
||||
|
||||
public static function hash(s:String) :String{
|
||||
//Convert to byteArray and send through hashBinary function
|
||||
// so as to only have complex code in one location
|
||||
var ba:ByteArray = new ByteArray();
|
||||
ba.writeUTFBytes(s);
|
||||
return hashBinary(ba);
|
||||
}
|
||||
/**
|
||||
* Performs the MD5 hash algorithm on a ByteArray.
|
||||
*
|
||||
* @param s The string to hash
|
||||
* @return A string containing the hash value of s
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 8.5
|
||||
* @tiptext
|
||||
*/
|
||||
public static function hashBinary( s:ByteArray ):String {
|
||||
// initialize the md buffers
|
||||
var a:int = 1732584193;
|
||||
var b:int = -271733879;
|
||||
var c:int = -1732584194;
|
||||
var d:int = 271733878;
|
||||
|
||||
// variables to store previous values
|
||||
var aa:int;
|
||||
var bb:int;
|
||||
var cc:int;
|
||||
var dd:int;
|
||||
|
||||
// create the blocks from the string and
|
||||
// save the length as a local var to reduce
|
||||
// lookup in the loop below
|
||||
var x:Array = createBlocks( s );
|
||||
var len:int = x.length;
|
||||
|
||||
// loop over all of the blocks
|
||||
for ( var i:int = 0; i < len; i += 16) {
|
||||
// save previous values
|
||||
aa = a;
|
||||
bb = b;
|
||||
cc = c;
|
||||
dd = d;
|
||||
|
||||
// Round 1
|
||||
a = ff( a, b, c, d, x[int(i+ 0)], 7, -680876936 ); // 1
|
||||
d = ff( d, a, b, c, x[int(i+ 1)], 12, -389564586 ); // 2
|
||||
c = ff( c, d, a, b, x[int(i+ 2)], 17, 606105819 ); // 3
|
||||
b = ff( b, c, d, a, x[int(i+ 3)], 22, -1044525330 ); // 4
|
||||
a = ff( a, b, c, d, x[int(i+ 4)], 7, -176418897 ); // 5
|
||||
d = ff( d, a, b, c, x[int(i+ 5)], 12, 1200080426 ); // 6
|
||||
c = ff( c, d, a, b, x[int(i+ 6)], 17, -1473231341 ); // 7
|
||||
b = ff( b, c, d, a, x[int(i+ 7)], 22, -45705983 ); // 8
|
||||
a = ff( a, b, c, d, x[int(i+ 8)], 7, 1770035416 ); // 9
|
||||
d = ff( d, a, b, c, x[int(i+ 9)], 12, -1958414417 ); // 10
|
||||
c = ff( c, d, a, b, x[int(i+10)], 17, -42063 ); // 11
|
||||
b = ff( b, c, d, a, x[int(i+11)], 22, -1990404162 ); // 12
|
||||
a = ff( a, b, c, d, x[int(i+12)], 7, 1804603682 ); // 13
|
||||
d = ff( d, a, b, c, x[int(i+13)], 12, -40341101 ); // 14
|
||||
c = ff( c, d, a, b, x[int(i+14)], 17, -1502002290 ); // 15
|
||||
b = ff( b, c, d, a, x[int(i+15)], 22, 1236535329 ); // 16
|
||||
|
||||
// Round 2
|
||||
a = gg( a, b, c, d, x[int(i+ 1)], 5, -165796510 ); // 17
|
||||
d = gg( d, a, b, c, x[int(i+ 6)], 9, -1069501632 ); // 18
|
||||
c = gg( c, d, a, b, x[int(i+11)], 14, 643717713 ); // 19
|
||||
b = gg( b, c, d, a, x[int(i+ 0)], 20, -373897302 ); // 20
|
||||
a = gg( a, b, c, d, x[int(i+ 5)], 5, -701558691 ); // 21
|
||||
d = gg( d, a, b, c, x[int(i+10)], 9, 38016083 ); // 22
|
||||
c = gg( c, d, a, b, x[int(i+15)], 14, -660478335 ); // 23
|
||||
b = gg( b, c, d, a, x[int(i+ 4)], 20, -405537848 ); // 24
|
||||
a = gg( a, b, c, d, x[int(i+ 9)], 5, 568446438 ); // 25
|
||||
d = gg( d, a, b, c, x[int(i+14)], 9, -1019803690 ); // 26
|
||||
c = gg( c, d, a, b, x[int(i+ 3)], 14, -187363961 ); // 27
|
||||
b = gg( b, c, d, a, x[int(i+ 8)], 20, 1163531501 ); // 28
|
||||
a = gg( a, b, c, d, x[int(i+13)], 5, -1444681467 ); // 29
|
||||
d = gg( d, a, b, c, x[int(i+ 2)], 9, -51403784 ); // 30
|
||||
c = gg( c, d, a, b, x[int(i+ 7)], 14, 1735328473 ); // 31
|
||||
b = gg( b, c, d, a, x[int(i+12)], 20, -1926607734 ); // 32
|
||||
|
||||
// Round 3
|
||||
a = hh( a, b, c, d, x[int(i+ 5)], 4, -378558 ); // 33
|
||||
d = hh( d, a, b, c, x[int(i+ 8)], 11, -2022574463 ); // 34
|
||||
c = hh( c, d, a, b, x[int(i+11)], 16, 1839030562 ); // 35
|
||||
b = hh( b, c, d, a, x[int(i+14)], 23, -35309556 ); // 36
|
||||
a = hh( a, b, c, d, x[int(i+ 1)], 4, -1530992060 ); // 37
|
||||
d = hh( d, a, b, c, x[int(i+ 4)], 11, 1272893353 ); // 38
|
||||
c = hh( c, d, a, b, x[int(i+ 7)], 16, -155497632 ); // 39
|
||||
b = hh( b, c, d, a, x[int(i+10)], 23, -1094730640 ); // 40
|
||||
a = hh( a, b, c, d, x[int(i+13)], 4, 681279174 ); // 41
|
||||
d = hh( d, a, b, c, x[int(i+ 0)], 11, -358537222 ); // 42
|
||||
c = hh( c, d, a, b, x[int(i+ 3)], 16, -722521979 ); // 43
|
||||
b = hh( b, c, d, a, x[int(i+ 6)], 23, 76029189 ); // 44
|
||||
a = hh( a, b, c, d, x[int(i+ 9)], 4, -640364487 ); // 45
|
||||
d = hh( d, a, b, c, x[int(i+12)], 11, -421815835 ); // 46
|
||||
c = hh( c, d, a, b, x[int(i+15)], 16, 530742520 ); // 47
|
||||
b = hh( b, c, d, a, x[int(i+ 2)], 23, -995338651 ); // 48
|
||||
|
||||
// Round 4
|
||||
a = ii( a, b, c, d, x[int(i+ 0)], 6, -198630844 ); // 49
|
||||
d = ii( d, a, b, c, x[int(i+ 7)], 10, 1126891415 ); // 50
|
||||
c = ii( c, d, a, b, x[int(i+14)], 15, -1416354905 ); // 51
|
||||
b = ii( b, c, d, a, x[int(i+ 5)], 21, -57434055 ); // 52
|
||||
a = ii( a, b, c, d, x[int(i+12)], 6, 1700485571 ); // 53
|
||||
d = ii( d, a, b, c, x[int(i+ 3)], 10, -1894986606 ); // 54
|
||||
c = ii( c, d, a, b, x[int(i+10)], 15, -1051523 ); // 55
|
||||
b = ii( b, c, d, a, x[int(i+ 1)], 21, -2054922799 ); // 56
|
||||
a = ii( a, b, c, d, x[int(i+ 8)], 6, 1873313359 ); // 57
|
||||
d = ii( d, a, b, c, x[int(i+15)], 10, -30611744 ); // 58
|
||||
c = ii( c, d, a, b, x[int(i+ 6)], 15, -1560198380 ); // 59
|
||||
b = ii( b, c, d, a, x[int(i+13)], 21, 1309151649 ); // 60
|
||||
a = ii( a, b, c, d, x[int(i+ 4)], 6, -145523070 ); // 61
|
||||
d = ii( d, a, b, c, x[int(i+11)], 10, -1120210379 ); // 62
|
||||
c = ii( c, d, a, b, x[int(i+ 2)], 15, 718787259 ); // 63
|
||||
b = ii( b, c, d, a, x[int(i+ 9)], 21, -343485551 ); // 64
|
||||
|
||||
a += aa;
|
||||
b += bb;
|
||||
c += cc;
|
||||
d += dd;
|
||||
}
|
||||
|
||||
// Finish up by concatening the buffers with their hex output
|
||||
return IntUtil.toHex( a ) + IntUtil.toHex( b ) + IntUtil.toHex( c ) + IntUtil.toHex( d );
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function f as defined in RFC
|
||||
*/
|
||||
private static function f( x:int, y:int, z:int ):int {
|
||||
return ( x & y ) | ( (~x) & z );
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function g as defined in RFC
|
||||
*/
|
||||
private static function g( x:int, y:int, z:int ):int {
|
||||
return ( x & z ) | ( y & (~z) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function h as defined in RFC
|
||||
*/
|
||||
private static function h( x:int, y:int, z:int ):int {
|
||||
return x ^ y ^ z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function i as defined in RFC
|
||||
*/
|
||||
private static function i( x:int, y:int, z:int ):int {
|
||||
return y ^ ( x | (~z) );
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic transformation function. The logic of ff, gg, hh, and
|
||||
* ii are all the same, minus the function used, so pull that logic
|
||||
* out and simplify the method bodies for the transoformation functions.
|
||||
*/
|
||||
private static function transform( func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int):int {
|
||||
var tmp:int = a + int( func( b, c, d ) ) + x + t;
|
||||
return IntUtil.rol( tmp, s ) + b;
|
||||
}
|
||||
|
||||
/**
|
||||
* ff transformation function
|
||||
*/
|
||||
private static function ff ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
|
||||
return transform( f, a, b, c, d, x, s, t );
|
||||
}
|
||||
|
||||
/**
|
||||
* gg transformation function
|
||||
*/
|
||||
private static function gg ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
|
||||
return transform( g, a, b, c, d, x, s, t );
|
||||
}
|
||||
|
||||
/**
|
||||
* hh transformation function
|
||||
*/
|
||||
private static function hh ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
|
||||
return transform( h, a, b, c, d, x, s, t );
|
||||
}
|
||||
|
||||
/**
|
||||
* ii transformation function
|
||||
*/
|
||||
private static function ii ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
|
||||
return transform( i, a, b, c, d, x, s, t );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string to a sequence of 16-word blocks
|
||||
* that we'll do the processing on. Appends padding
|
||||
* and length in the process.
|
||||
*
|
||||
* @param s The string to split into blocks
|
||||
* @return An array containing the blocks that s was
|
||||
* split into.
|
||||
*/
|
||||
private static function createBlocks( s:ByteArray ):Array {
|
||||
var blocks:Array = new Array();
|
||||
var len:int = s.length * 8;
|
||||
var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
|
||||
for( var i:int = 0; i < len; i += 8 ) {
|
||||
blocks[ int(i >> 5) ] |= ( s[ i / 8 ] & mask ) << ( i % 32 );
|
||||
}
|
||||
|
||||
// append padding and length
|
||||
blocks[ int(len >> 5) ] |= 0x80 << ( len % 32 );
|
||||
blocks[ int(( ( ( len + 64 ) >>> 9 ) << 4 ) + 14) ] = len;
|
||||
return blocks;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
/* Licensed under a Creative Creative Commons Attribution 3.0 Unported License */
|
||||
/* without any warranty express or implied */
|
||||
/* http://creativecommons.org/licenses/by/3.0/ */
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
/* Block TEA (xxtea) Tiny Encryption Algorithm implementation in ActionScript */
|
||||
/* (c) Wowza Media Systems, Inc 2010: www.wowzamedia.com */
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
/* Block TEA (xxtea) Tiny Encryption Algorithm implementation in JavaScript */
|
||||
/* (c) Chris Veness 2002-2010: www.movable-type.co.uk/tea-block.html */
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
/* Algorithm: David Wheeler & Roger Needham, Cambridge University Computer Lab */
|
||||
/* http://www.cl.cam.ac.uk/ftp/papers/djw-rmn/djw-rmn-tea.html (1994) */
|
||||
/* http://www.cl.cam.ac.uk/ftp/users/djw3/xtea.ps (1997) */
|
||||
/* http://www.cl.cam.ac.uk/ftp/users/djw3/xxtea.ps (1998) */
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
package ckaction.act {
|
||||
|
||||
public class TEA {
|
||||
|
||||
/*
|
||||
* encrypt text using Corrected Block TEA (xxtea) algorithm
|
||||
*
|
||||
* @param {string} plaintext String to be encrypted (multi-byte safe)
|
||||
* @param {string} password Password to be used for encryption (1st 16 chars)
|
||||
* @returns {string} encrypted text
|
||||
*/
|
||||
public static function encrypt(plaintext:String, password:String):String {
|
||||
if (plaintext.length == 0) return ""; // nothing to encrypt
|
||||
|
||||
// convert string to array of longs after converting any multi-byte chars to UTF-8
|
||||
var v:Array = charsToLongs(strToChars(plaintext));
|
||||
if (v.length <= 1) v[1] = 0; // algorithm doesn't work for n<2 so fudge by adding a null
|
||||
// simply convert first 16 chars of password as key
|
||||
var k:Array = charsToLongs(strToChars(password.substr(0, 16)));
|
||||
var n:Number = v.length;
|
||||
|
||||
// ---- <TEA coding> ----
|
||||
|
||||
var z:Number = v[n-1], y:Number = v[0], delta:Number = 0x9E3779B9;
|
||||
var mx:Number, e:Number, q:Number = Math.floor(6 + 52/n), sum:Number = 0;
|
||||
|
||||
while (q-- > 0) { // 6 + 52/n operations gives between 6 & 32 mixes on each word
|
||||
sum += delta;
|
||||
e = sum>>>2 & 3;
|
||||
for (var p:Number = 0; p < n; p++) {
|
||||
y = v[(p+1)%n];
|
||||
mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
|
||||
z = v[p] += mx;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- </TEA> ----
|
||||
|
||||
var ciphertext:Array = longsToChars(v);
|
||||
|
||||
return charsToHex(ciphertext);
|
||||
}
|
||||
|
||||
/*
|
||||
* decrypt text using Corrected Block TEA (xxtea) algorithm
|
||||
*
|
||||
* @param {string} ciphertext String to be decrypted
|
||||
* @param {string} password Password to be used for decryption (1st 16 chars)
|
||||
* @returns {string} decrypted text
|
||||
*/
|
||||
public static function decrypt(ciphertext:String, password:String):String {
|
||||
|
||||
if (ciphertext.length == 0) return "";
|
||||
var v:Array = charsToLongs(hexToChars(ciphertext));
|
||||
var k:Array = charsToLongs(strToChars(password.substr(0, 16)));
|
||||
var n:Number = v.length;
|
||||
|
||||
// ---- <TEA decoding> ----
|
||||
|
||||
var z:Number = v[n-1], y:Number = v[0], delta:Number = 0x9E3779B9;
|
||||
var mx:Number, e:Number, q:Number = Math.floor(6 + 52/n), sum:Number = q*delta;
|
||||
|
||||
while (sum != 0) {
|
||||
e = sum>>>2 & 3;
|
||||
for (var p:Number = n-1; p >= 0; p--) {
|
||||
z = v[p>0 ? p-1 : n-1];
|
||||
mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
|
||||
y = v[p] -= mx;
|
||||
}
|
||||
sum -= delta;
|
||||
}
|
||||
|
||||
// ---- </TEA> ----
|
||||
|
||||
var plaintext:Array = longsToChars(v);
|
||||
|
||||
return charsToStr(plaintext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private methods.
|
||||
*/
|
||||
private static function charsToLongs(chars:Array):Array {
|
||||
var temp:Array = new Array(Math.ceil(chars.length/4));
|
||||
for (var i:Number = 0; i<temp.length; i++) {
|
||||
temp[i] = chars[i*4] + (chars[i*4+1]<<8) + (chars[i*4+2]<<16) + (chars[i*4+3]<<24);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
private static function longsToChars(longs:Array):Array {
|
||||
var codes:Array = new Array();
|
||||
for (var i:Number = 0; i<longs.length; i++) {
|
||||
codes.push(longs[i] & 0xFF, longs[i]>>>8 & 0xFF, longs[i]>>>16 & 0xFF, longs[i]>>>24 & 0xFF);
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
private static function longToChars(longs:Number):Array {
|
||||
var codes:Array = new Array();
|
||||
codes.push(longs & 0xFF, longs>>>8 & 0xFF, longs>>>16 & 0xFF, longs>>>24 & 0xFF);
|
||||
return codes;
|
||||
}
|
||||
|
||||
private static function charsToHex(chars:Array):String {
|
||||
var result:String = new String("");
|
||||
var hexes:Array = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
|
||||
for (var i:Number = 0; i<chars.length; i++) {
|
||||
result += hexes[chars[i] >> 4] + hexes[chars[i] & 0xf];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static function hexToChars(hex:String):Array {
|
||||
var codes:Array = new Array();
|
||||
for (var i:Number = (hex.substr(0, 2) == "0x") ? 2 : 0; i<hex.length; i+=2) {
|
||||
codes.push(parseInt(hex.substr(i, 2), 16));
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
private static function charsToStr(chars:Array):String {
|
||||
var result:String = new String("");
|
||||
for (var i:Number = 0; i<chars.length; i++) {
|
||||
result += String.fromCharCode(chars[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static function strToChars(str:String):Array {
|
||||
var codes:Array = new Array();
|
||||
for (var i:Number = 0; i<str.length; i++) {
|
||||
codes.push(str.charCodeAt(i));
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package ckaction.act {
|
||||
|
||||
public class XML2JSON {
|
||||
|
||||
private static var _arrays: Array;
|
||||
|
||||
public static function parse(node: * ): Object {
|
||||
var obj: Object = {};
|
||||
var numOfChilds: int = node.children().length();
|
||||
for (var i: int = 0; i < numOfChilds; i++) {
|
||||
var childNode: * = node.children()[i];
|
||||
var childNodeName: String = childNode.name();
|
||||
var value: * ;
|
||||
if (childNode.children().length() == 1 && childNode.children()[0].name() == null) {
|
||||
if (childNode.attributes().length() > 0) {
|
||||
value = {
|
||||
_content: childNode.children()[0].toString()
|
||||
};
|
||||
var numOfAttributes: int = childNode.attributes().length();
|
||||
for (var j: int = 0; j < numOfAttributes; j++) {
|
||||
value[childNode.attributes()[j].name().toString()] = childNode.attributes()[j];
|
||||
}
|
||||
} else {
|
||||
value = childNode.children()[0].toString();
|
||||
}
|
||||
} else {
|
||||
value = parse(childNode);
|
||||
}
|
||||
if (obj[childNodeName]) {
|
||||
if (getTypeof(obj[childNodeName]) == "array") {
|
||||
obj[childNodeName].push(value);
|
||||
} else {
|
||||
obj[childNodeName] = [obj[childNodeName], value];
|
||||
}
|
||||
} else if (isArray(childNodeName)) {
|
||||
obj[childNodeName] = [value];
|
||||
} else {
|
||||
obj[childNodeName] = value;
|
||||
}
|
||||
}
|
||||
numOfAttributes = node.attributes().length();
|
||||
for (i = 0; i < numOfAttributes; i++) {
|
||||
obj[node.attributes()[i].name().toString()] = node.attributes()[i];
|
||||
}
|
||||
if (numOfChilds == 0) {
|
||||
if (numOfAttributes == 0) {
|
||||
obj = "";
|
||||
} else {
|
||||
obj._content = "";
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
public static function get arrays(): Array {
|
||||
if (!_arrays) {
|
||||
_arrays = [];
|
||||
}
|
||||
return _arrays;
|
||||
}
|
||||
public static function set arrays(a: Array): void {
|
||||
_arrays = a;
|
||||
}
|
||||
private static function isArray(nodeName: String): Boolean {
|
||||
var numOfArrays: int = _arrays ? _arrays.length : 0;
|
||||
for (var i: int = 0; i < numOfArrays; i++) {
|
||||
if (nodeName == _arrays[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static function getTypeof(o: * ): String {
|
||||
if (typeof (o) == "object") {
|
||||
if (o.length == null) {
|
||||
return "object";
|
||||
} else if (typeof (o.length) == "number") {
|
||||
return "array";
|
||||
} else {
|
||||
return "object";
|
||||
}
|
||||
} else {
|
||||
return typeof (o);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package ckaction.act {
|
||||
import ckaction.C.C;
|
||||
import com.hurlant.crypto.symmetric.DESKey;
|
||||
import com.hurlant.crypto.symmetric.ECBMode;
|
||||
import com.hurlant.util.Base64;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.events.ErrorEvent;
|
||||
import flash.display.BitmapData;
|
||||
import flash.geom.Rectangle;
|
||||
|
||||
public class des {
|
||||
public function des() {
|
||||
|
||||
}
|
||||
public static function getString(s: String): String {
|
||||
// constructor code
|
||||
var codes: String = C.CEKEY;
|
||||
var codes2: String = "ckplayerDesKey";
|
||||
var de: String = s;
|
||||
var type: String = s.substr(0, 3);
|
||||
s = decodeURI(s);
|
||||
s=script.replace(s,[" "],["+"]);
|
||||
if (type == "CE:" || type == "CK:") {
|
||||
if (type == "CE:") {
|
||||
s = s.replace("CE:", "");
|
||||
} else {
|
||||
s = s.replace("CK:", "");
|
||||
}
|
||||
try {
|
||||
var b64: ByteArray = Base64.decodeToByteArray(s);
|
||||
if (type == "CE:") {
|
||||
//trace("codes",codes);
|
||||
de = decrypt(codes, b64);
|
||||
} else {
|
||||
de = decrypt(codes2, b64);
|
||||
}
|
||||
} catch (event: ErrorEvent) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
if (de.indexOf("base64,") > -1) {
|
||||
de = de.split("base64,")[1]
|
||||
}
|
||||
return de.split("\n").join("").split("\r").join("").split("\n\r").join("").split("\r\n").join("");
|
||||
}
|
||||
|
||||
public static function getByteArray(s: String): ByteArray {
|
||||
// constructor code
|
||||
var codes: String = C.CEKEY;
|
||||
var codes2: String = "ckplayerDesKey";
|
||||
var de: String = s;
|
||||
s = decodeURI(s).split("\n").join("").split("\r").join("").split("\n\r").join("").split("\r\n").join("");
|
||||
s=script.replace(s,[" "],["+"]);
|
||||
var type: String = s.substr(0, 3);
|
||||
if (type == "CE:" || type == "CK:") {
|
||||
if (type == "CE:") {
|
||||
s = s.replace("CE:", "");
|
||||
} else {
|
||||
s = s.replace("CK:", "");
|
||||
}
|
||||
try {
|
||||
var b64: ByteArray = Base64.decodeToByteArray(s);
|
||||
if (type == "CE:") {
|
||||
de = decrypt(codes, b64);
|
||||
} else {
|
||||
de = decrypt(codes2, b64);
|
||||
}
|
||||
} catch (event: ErrorEvent) {
|
||||
return new ByteArray();
|
||||
}
|
||||
}
|
||||
if (de.indexOf("base64,") > -1) {
|
||||
de = de.split("base64,")[1]
|
||||
}
|
||||
try {
|
||||
return Base64.decodeToByteArray(de);
|
||||
} catch (event: ErrorEvent) {
|
||||
return new ByteArray();
|
||||
}
|
||||
return new ByteArray();
|
||||
}
|
||||
public static function getVString(s: String): String {
|
||||
// constructor code
|
||||
var de: String = s;
|
||||
s = decodeURI(s);
|
||||
s=script.replace(s,[" "],["+"]);
|
||||
try {
|
||||
var b64: ByteArray = Base64.decodeToByteArray(s);
|
||||
de = decrypt(C.CVKEY, b64);
|
||||
} catch (event: ErrorEvent) {
|
||||
return de;
|
||||
}
|
||||
return de;
|
||||
}
|
||||
private static function decrypt(key: String, data: ByteArray): String {
|
||||
//trace("\n执行解密方法,key:", key, ",需要解密的字符串:", data);
|
||||
//实验化key的Bytearray对象,给DESKey使用
|
||||
var b_keyByteArray: ByteArray = new ByteArray();
|
||||
b_keyByteArray.writeUTFBytes(key);
|
||||
//实例化DESKey
|
||||
var b_desKey: DESKey = new DESKey(b_keyByteArray);
|
||||
var b_ecb: ECBMode = new ECBMode(b_desKey);
|
||||
var b_byteArray: ByteArray = new ByteArray();
|
||||
b_byteArray.writeBytes(data);
|
||||
//执行解密
|
||||
b_ecb.decrypt(b_byteArray);
|
||||
|
||||
return convertByteArrayToString(b_byteArray);
|
||||
}
|
||||
private static function convertByteArrayToString(bytes: ByteArray): String {
|
||||
var str: String;
|
||||
if (bytes) {
|
||||
bytes.position = 0;
|
||||
str = bytes.readUTFBytes(bytes.length);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ckaction.act {
|
||||
import flash.display.Loader;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.net.URLRequest;
|
||||
import flash.display.LoaderInfo;
|
||||
public class httpload {
|
||||
private var load: Loader = null;
|
||||
private var file: String = "";
|
||||
private var successFun: Function = null;
|
||||
public function httpload(url: String, success: Function) {
|
||||
// constructor code
|
||||
successFun = success;
|
||||
file = url;
|
||||
loader();
|
||||
}
|
||||
private function loader(): void {
|
||||
load = new Loader();
|
||||
load.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
|
||||
load.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); //监听加载失败
|
||||
load.load(new URLRequest(file));
|
||||
}
|
||||
private function completeHandler(event: Event): void {
|
||||
successFun(load);
|
||||
remove();
|
||||
}
|
||||
private function errorHandler(event: IOErrorEvent): void {
|
||||
remove();
|
||||
successFun(null);
|
||||
}
|
||||
private function remove(): void {
|
||||
load.removeEventListener(Event.COMPLETE, completeHandler);
|
||||
load.removeEventListener(IOErrorEvent.IO_ERROR, errorHandler);
|
||||
load = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package ckaction.act {
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLRequest;
|
||||
import ckaction.act.XML2JSON;
|
||||
import flash.events.ErrorEvent;
|
||||
import ckaction.C.C;
|
||||
import flash.net.URLVariables;
|
||||
|
||||
public class loadXml {
|
||||
private var f: Function; //加载成功或失败都返回该函数
|
||||
private var l: URLLoader = null;
|
||||
public function loadXml(m: String, c: Function, met: String = "get"): void {
|
||||
if(!m){
|
||||
trace("没有文件路径");
|
||||
c(null);
|
||||
return;
|
||||
}
|
||||
f = c;
|
||||
var r: URLRequest = new URLRequest(m);
|
||||
//var params: URLVariables = new URLVariables();
|
||||
//params["path"]=C.PATH["path"]+C.PATH["file"];
|
||||
//r.data=params;
|
||||
//r.method = met;
|
||||
l = new URLLoader();
|
||||
l.addEventListener(Event.COMPLETE, com);
|
||||
l.addEventListener(IOErrorEvent.IO_ERROR, err);
|
||||
l.load(r);
|
||||
}
|
||||
private function remove(): void {
|
||||
l.removeEventListener(Event.COMPLETE, com);
|
||||
l.removeEventListener(IOErrorEvent.IO_ERROR, err);
|
||||
}
|
||||
private function com(event: Event): void {
|
||||
var str: String = event.currentTarget.data.toString();
|
||||
if (str.indexOf("<?xml version=") > -1 || str.indexOf("</") > -1) {
|
||||
var xml: XML = new XML(event.currentTarget.data);
|
||||
if (xml) {
|
||||
try {
|
||||
analysis(xml);
|
||||
} catch (event: Error) {
|
||||
f(null);
|
||||
}
|
||||
} else {
|
||||
f(null);
|
||||
}
|
||||
} else if (str.indexOf("{") == 0 || str.indexOf("[") == 0) {
|
||||
try {
|
||||
var json: Object = JSON.parse(event.currentTarget.data);
|
||||
if (json != null) {
|
||||
|
||||
f(json);
|
||||
} else {
|
||||
f(null);
|
||||
}
|
||||
} catch (event: Error) {
|
||||
new log(event);
|
||||
trace(event);
|
||||
f(null);
|
||||
}
|
||||
} else {
|
||||
f(str);
|
||||
}
|
||||
remove();
|
||||
}
|
||||
private function analysis(xml: XML): void {
|
||||
var obj: Object = XML2JSON.parse(xml);
|
||||
try {
|
||||
f(obj);
|
||||
} catch (event: Error) {
|
||||
f(null);
|
||||
}
|
||||
}
|
||||
private function err(event: IOErrorEvent) {
|
||||
f(null);
|
||||
remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ckaction.act {
|
||||
import ckaction.C.C;
|
||||
|
||||
public class log {
|
||||
|
||||
public function log(val: * ) {
|
||||
// constructor code
|
||||
//trace("log:", val);
|
||||
if (C.CONFIG["flashvars"]["debug"]) {
|
||||
script.callJs("console.log", val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package ckaction.act {
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.IEventDispatcher;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestHeader;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.net.URLStream;
|
||||
import flash.net.URLVariables;
|
||||
public class requestController {
|
||||
private var stream: URLLoader;
|
||||
private var req: URLRequest;
|
||||
public function requestController(method: String, url: String,paramsObj:Object=null ) {
|
||||
stream = new URLLoader();
|
||||
req = new URLRequest(url);
|
||||
if(paramsObj){
|
||||
var params: URLVariables=new URLVariables();
|
||||
for(var k:String in paramsObj){
|
||||
params[k]=paramsObj[k];
|
||||
}
|
||||
req.data = params;
|
||||
}
|
||||
req.method = method;
|
||||
//setHeaders(request);
|
||||
stream.addEventListener(Event.COMPLETE, completeHandler);
|
||||
stream.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
|
||||
stream.load(req);
|
||||
}
|
||||
private function ioErrorHandler(event: Event): void {
|
||||
//将异常事件发出,由调用者处理
|
||||
trace("error",event);
|
||||
}
|
||||
private function completeHandler(event: Event): void {
|
||||
//trace(event.currentTarget.data);
|
||||
}
|
||||
public function dispose(): void {
|
||||
stream.removeEventListener(Event.COMPLETE, completeHandler);
|
||||
stream.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
|
||||
stream = null;
|
||||
req = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,679 @@
|
||||
package ckaction.act {
|
||||
import flash.external.ExternalInterface;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.navigateToURL;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.events.ErrorEvent;
|
||||
//import ckaction.C.C;
|
||||
|
||||
public class script {
|
||||
|
||||
public static function formatTime(seconds: Number = 0, hourc: int = 0, hours: int = 0): Array { //格式化秒数为时分秒
|
||||
//seconds = 3800;
|
||||
var timeh: int = Math.floor(seconds / 3600),
|
||||
timei = Math.floor(Math.floor(seconds % 3600) / 60),
|
||||
timeI = Math.floor(seconds / 60),
|
||||
times = Math.floor(Math.floor(seconds % 60));
|
||||
if (hourc > 0) {
|
||||
timeh += (hours - hourc + 1);
|
||||
if (timeh < 0) {
|
||||
timeh = 24 + timeh;
|
||||
}
|
||||
}
|
||||
var array: Array = [
|
||||
timeh < 10 ? "0" + timeh : timeh.toString(),
|
||||
timei < 10 ? "0" + timei : timei.toString(),
|
||||
timeI < 10 ? "0" + timeI : timeI.toString(),
|
||||
times < 10 ? "0" + times : times.toString(),
|
||||
seconds < 10 ? "0" + seconds : seconds.toString()
|
||||
];
|
||||
return array;
|
||||
}
|
||||
public static function formatInsertTime(str: String = "", total: Number = 0): Array {
|
||||
//trace(str,total);
|
||||
if (!str) {
|
||||
return null;
|
||||
}
|
||||
var arr: Array = str.split(",");
|
||||
var newArr: Array = [];
|
||||
for (var i: int = 0; i < arr.length; i++) {
|
||||
var s: String = arr[i].toString();
|
||||
if (s.indexOf("%") > -1) {
|
||||
newArr.push(total * Number(s.replace("%", "")) * 0.01);
|
||||
} else {
|
||||
newArr.push(Number(s));
|
||||
}
|
||||
}
|
||||
//trace("jfuj",newArr);
|
||||
return newArr;
|
||||
}
|
||||
public static function formatM3u8Definition(url: String, n: int = 0, tags: Array = null, name: Array = null): String {
|
||||
var i: int = 0;
|
||||
if (!name) {
|
||||
return "";
|
||||
}
|
||||
if (tags.length > 0) {
|
||||
var ti: int = 0;
|
||||
for (i = 0; i < tags.length; i++) {
|
||||
if (url.indexOf(tags[i]) > -1) {
|
||||
ti = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ti < name.length) {
|
||||
return name[ti];
|
||||
} else {
|
||||
return name[name.length - 1];
|
||||
}
|
||||
|
||||
} else {
|
||||
if (n < name.length) {
|
||||
return name[n];
|
||||
} else {
|
||||
return name[name.length - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function getNowDate(b: Boolean = true): String { //获取当前时间
|
||||
var nowDate: Date = new Date();
|
||||
var month: int = nowDate.month + 1;
|
||||
var date: int = nowDate.date;
|
||||
var hours: int = nowDate.hours;
|
||||
var minutes: int = nowDate.minutes;
|
||||
var seconds: int = nowDate.seconds;
|
||||
var tMonth: String = "",
|
||||
tDate: String = "",
|
||||
tHours: String = "",
|
||||
tMinutes: String = "",
|
||||
tSeconds: String = ""
|
||||
tSeconds = (seconds < 10) ? "0" + seconds : seconds + "";
|
||||
tMinutes = (minutes < 10) ? "0" + minutes : minutes + "";
|
||||
tHours = (hours < 10) ? "0" + hours : hours + "";
|
||||
tDate = (date < 10) ? "0" + date : date + "";
|
||||
tMonth = (month < 10) ? "0" + month : month + "";
|
||||
if (b) {
|
||||
return tMonth + "/" + tDate + " " + tHours + ":" + tMinutes + ":" + tSeconds;
|
||||
}
|
||||
return nowDate.fullYear + tMonth + tDate + tHours + tMinutes + tSeconds;
|
||||
}
|
||||
public static function getFileExt(filepath: String = null): String { //判断后缀,和rtmp协议
|
||||
if (filepath != "") {
|
||||
if (filepath.substr(0, 7) == "rtmp://") {
|
||||
return "rtmp";
|
||||
}
|
||||
if (filepath.indexOf("?") > -1) {
|
||||
filepath = filepath.split("?")[0];
|
||||
}
|
||||
var pos: String = "." + filepath.replace(/.+\./, "");
|
||||
return pos;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public static function arrSort(arr: Array): Array { //对二维数组进行冒泡排序
|
||||
var temp: Array = [];
|
||||
for (var i: int = 0; i < arr.length; i++) {
|
||||
for (var j: int = 0; j < arr.length - i; j++) {
|
||||
if (arr[j + 1] && arr[j][3] < arr[j + 1][3]) {
|
||||
temp = arr[j + 1];
|
||||
arr[j + 1] = arr[j];
|
||||
arr[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
public static function getCoor(obj: Object): Object {
|
||||
/*根据宽高计算元素的长宽和坐标
|
||||
obj={
|
||||
stageW=播放器的宽
|
||||
stageH=播放器的高
|
||||
eleW=元件的宽
|
||||
eleH=元件的高
|
||||
stretched=缩放形式:0=原始大小,1=自动缩放,2=只有当元件的宽或高大于播放器宽高时才进行缩放,3=参考播放器宽高,4=宽度参考播放器宽、高度自动,5=高度参考播放器高、宽度自动
|
||||
align=水平对齐方式 left,center,right
|
||||
vAlign=垂直对齐方式 top.middle,bottom
|
||||
spacingLeft=左方预留间距
|
||||
spacingTop=上方预留间距
|
||||
spacingRight=右方预留间距
|
||||
spacingBottom=下方预留间距
|
||||
}
|
||||
*/
|
||||
var nObj: Object = mergeObject({
|
||||
stageW: 0,
|
||||
stageH: 0,
|
||||
eleW: 0,
|
||||
eleH: 0,
|
||||
stretched: 0,
|
||||
align: "center",
|
||||
vAlign: "middle",
|
||||
spacingLeft: 0,
|
||||
spacingTop: 0,
|
||||
spacingRight: 0,
|
||||
spacingBottom: 0
|
||||
}, obj);
|
||||
//traceObject(nObj);
|
||||
var stageW: int = nObj["stageW"] - nObj["spacingLeft"] - nObj["spacingRight"];
|
||||
var stageH: int = nObj["stageH"] - nObj["spacingTop"] - nObj["spacingBottom"];
|
||||
var eleW: int = nObj["eleW"];
|
||||
var eleH: int = nObj["eleH"];
|
||||
var w: int = eleW,
|
||||
h: int = eleH,
|
||||
x: int = 0,
|
||||
y: int = 0;
|
||||
|
||||
if (nObj["stretched"] == 2) {
|
||||
if (eleW > stageW) {
|
||||
nObj["stretched"] = 4;
|
||||
}
|
||||
if (eleH > stageH) {
|
||||
nObj["stretched"] = 5;
|
||||
}
|
||||
if (eleW > stageW && eleH > stageH) {
|
||||
nObj["stretched"] = 1;
|
||||
}
|
||||
}
|
||||
switch (nObj["stretched"]) {
|
||||
case 1:
|
||||
if (stageW / stageH < eleW / eleH) {
|
||||
w = stageW;
|
||||
h = w * eleH / eleW;
|
||||
} else {
|
||||
h = stageH;
|
||||
w = h * eleW / eleH;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
w = stageW;
|
||||
h = stageH;
|
||||
break;
|
||||
case 4:
|
||||
w = stageW;
|
||||
h = w * eleH / eleW;
|
||||
break;
|
||||
case 5:
|
||||
h = stageH;
|
||||
w = h * eleW / eleH;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
switch (nObj["align"]) {
|
||||
case "left":
|
||||
x = nObj["spacingLeft"];
|
||||
break;
|
||||
case "center":
|
||||
x = (stageW - w) * 0.5 + nObj["spacingLeft"];
|
||||
break;
|
||||
case "right":
|
||||
x = stageW - w + nObj["spacingLeft"];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
switch (nObj["vAlign"]) {
|
||||
case "top":
|
||||
y = nObj["spacingTop"];
|
||||
break;
|
||||
case "middle":
|
||||
y = (stageH - h) * 0.5 + nObj["spacingTop"];
|
||||
break;
|
||||
case "bottom":
|
||||
y = stageH - h + nObj["spacingTop"];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
//trace(w,h,x,y);
|
||||
return {
|
||||
width: w,
|
||||
height: h,
|
||||
x: x,
|
||||
y: y
|
||||
};
|
||||
}
|
||||
public static function mergeOldFlashvars(nObj: Object, oObj: Object): Object {
|
||||
for (var k: String in oObj) {
|
||||
switch (k) {
|
||||
case "p":
|
||||
if (Number(oObj[k]) == 1) {
|
||||
nObj["autoplay"] = true;
|
||||
} else {
|
||||
nObj["autoplay"] = false;
|
||||
}
|
||||
break;
|
||||
case "lv":
|
||||
if (Number(oObj[k]) == 1) {
|
||||
nObj["live"] = true;
|
||||
} else {
|
||||
nObj["live"] = false;
|
||||
}
|
||||
break
|
||||
case "i":
|
||||
nObj["poster"] = oObj[k];
|
||||
break;
|
||||
case "v":
|
||||
nObj["volume"] = Number(oObj[k]) * 0.01;
|
||||
break;
|
||||
case "h":
|
||||
var h: int = Number(oObj[k]);
|
||||
var q: String ="";
|
||||
if(oObj.hasOwnProperty("q")){
|
||||
q = oObj["q"];
|
||||
}
|
||||
switch (h) {
|
||||
case 1:
|
||||
q = q != "" ?"frames_"+ q : "frames_start";
|
||||
break;
|
||||
case 2:
|
||||
q = q != "" ? "time_"+q : "time_start";
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
q = q != "" ? q : "start"
|
||||
break;
|
||||
}
|
||||
nObj["drag"] = h > 0 ? q : "";
|
||||
break;
|
||||
case "g":
|
||||
nObj["seek"] = Number(oObj[k]);
|
||||
break;
|
||||
case "er":
|
||||
nObj["error"] = oObj[k];
|
||||
break;
|
||||
case "k":
|
||||
if (oObj["n"] != "" && oObj["k"] != "") {
|
||||
var arrk: Array = oObj["k"].toString().split("|");
|
||||
var arrn: Array = oObj["n"].toString().split("|");
|
||||
if (arrk.length == arrn.length) {
|
||||
var arrx: Array = [];
|
||||
for (var i: int = 0; i < arrk.length; i++) {
|
||||
arrx.push({
|
||||
time: arrk[i],
|
||||
words: arrn[i]
|
||||
});
|
||||
|
||||
}
|
||||
nObj["promptSpot"] = arrx;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return nObj;
|
||||
}
|
||||
public static function simpleMergeObject(newObj: Object, oldObject: Object): Object { //简单形式直接替换对象
|
||||
//简单合并对象
|
||||
for (var k: String in oldObject) {
|
||||
newObj[k] = oldObject[k];
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
public static function supplementObject(newObj: Object, oldObject: Object): Object { //把旧对象合并到新对象里,主要用来补充参数,即如果原对象中包含了该参数就不需要再加入了
|
||||
|
||||
for (var k: String in oldObject) {
|
||||
if (!newObj.hasOwnProperty(k)) {
|
||||
newObj[k] = oldObject[k];
|
||||
} else {
|
||||
if (!newObj[k] || k == "volume") {
|
||||
if(getType(newObj[k])=="number"){
|
||||
newObj[k] = Number(oldObject[k]);
|
||||
}
|
||||
else{
|
||||
newObj[k] = oldObject[k];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
public static function formatSsl(str:String):String{
|
||||
var arr:Array=str.split("");
|
||||
var newStr:String="";
|
||||
for(var i:int=0; i<str.length; i++){
|
||||
if(str.charAt(i)>='0' && str.charAt(i)<='9'){
|
||||
newStr+=arr[i];
|
||||
}else if((str.charAt(i)>='a' && str.charAt(i)<='z') || (str.charAt(i)>='A' && str.charAt(i) <= 'Z')){
|
||||
newStr+=arr[i];
|
||||
}
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
public static function mergeObject(obj: Object = null, old: Object = null): Object { //把旧对象合并到新对象里,主要用来格式化参数
|
||||
function sendObj(nObj: Object, oObj: Object): Object {
|
||||
for (var k: String in oObj) {
|
||||
if (oObj[k] != undefined) {
|
||||
//trace(k,nObj[k] , getType(nObj[k]));
|
||||
var type: String = "";
|
||||
if (nObj.hasOwnProperty(k)) {
|
||||
type = getType(nObj[k]);
|
||||
|
||||
if (oObj[k]) {
|
||||
//trace(k,nObj[k],oObj[k],type,getType(nObj[k]),typeof(nObj[k]));
|
||||
switch (type) {
|
||||
case "object":
|
||||
nObj[k] = sendObj(nObj[k], oObj[k]);
|
||||
break;
|
||||
case "boolean":
|
||||
nObj[k] = (oObj[k] != "false" && oObj[k] != false) ? true : false;
|
||||
break;
|
||||
case "number":
|
||||
nObj[k] = Number(oObj[k]);
|
||||
//trace(k,nObj[k]);
|
||||
break;
|
||||
default:
|
||||
nObj[k] = oObj[k];
|
||||
if(nObj[k]=="true"){
|
||||
nObj[k]=true;
|
||||
}
|
||||
if(nObj[k]=="false"){
|
||||
nObj[k]=false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (type == "number" && (oObj[k] == 0 || oObj[k] == "0")) {
|
||||
nObj[k] = 0;
|
||||
}
|
||||
if(oObj[k]=="true"){
|
||||
nObj[k] =true;
|
||||
}
|
||||
if(oObj[k]=="false"){
|
||||
nObj[k] =false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (oObj[k]) {
|
||||
nObj[k] = oObj[k];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return nObj;
|
||||
}
|
||||
return sendObj(obj, old);
|
||||
}
|
||||
|
||||
public static function getStringLen(str): int { //计算字符长度,中文算2,字母数字算1
|
||||
var len: int = 0;
|
||||
for (var i: int = 0; i < str.length; i++) {
|
||||
if (str.charCodeAt(i) > 127 || str.charCodeAt(i) == 94) {
|
||||
len += 2;
|
||||
} else {
|
||||
len++;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
public static function copyObject(obj: Object): * { //复制对象
|
||||
var newObj: ByteArray = new ByteArray()
|
||||
newObj.writeObject(obj);
|
||||
newObj.position = 0;
|
||||
return newObj.readObject();
|
||||
}
|
||||
public static function getLen(str: String = ""): Number { //获取字符的长度
|
||||
if (!str) {
|
||||
return 0;
|
||||
}
|
||||
var digital: int = 0; //数字
|
||||
var character: int = 0; //字母
|
||||
var space: int = 0; //空格
|
||||
var other: int = 0; //其它字符
|
||||
for (var i: int = 0; i < str.length; i++) {
|
||||
if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
|
||||
digital++;
|
||||
} else if ((str.charAt(i) >= 'a' && str.charAt(i) <= 'z') || (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z')) {
|
||||
character++;
|
||||
} else if (str.charAt(i) == ' ') {
|
||||
space++;
|
||||
} else {
|
||||
other++;
|
||||
}
|
||||
}
|
||||
return (digital + character + space + other * 2) * 0.5
|
||||
}
|
||||
|
||||
public static function addListenerArr(listenerArr: Array, ele: String = "", fun: String = ""): Array { //添加监听函数数组
|
||||
if (ele != "" && fun != "") {
|
||||
var have: Boolean = false;
|
||||
for (var i: int = 0; i < listenerArr.length; i++) {
|
||||
var arr = listenerArr[i];
|
||||
if (arr[0] == ele && arr[1] == fun) {
|
||||
have = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!have) {
|
||||
listenerArr.push([ele, fun]);
|
||||
}
|
||||
}
|
||||
return listenerArr;
|
||||
}
|
||||
|
||||
public static function removeListenerArr(listenerArr: Array, ele: String = "", fun: String = ""): Array { //删除监听函数数组
|
||||
if (ele != "" && fun != "") {
|
||||
for (var i: int = 0; i < listenerArr.length; i++) {
|
||||
var arr = listenerArr[i];
|
||||
if (arr[0] == ele && arr[1] == fun) {
|
||||
listenerArr.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return listenerArr;
|
||||
}
|
||||
public static function callJs(js: String, val: *= null,val2:*=null): void {
|
||||
//trace(js);
|
||||
var arr: Array = js.split(".");
|
||||
if (arr[0] == "" || !ExternalInterface.available) {
|
||||
return;
|
||||
}
|
||||
if(val2 != null){
|
||||
if (val != null) {
|
||||
try {
|
||||
ExternalInterface.call(js, val,val2);
|
||||
} catch (event:Error) {
|
||||
new log(event)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
ExternalInterface.call(js,val2);
|
||||
} catch (event:Error) {
|
||||
new log(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (val != null) {
|
||||
try {
|
||||
ExternalInterface.call(js, val);
|
||||
} catch (event:Error) {
|
||||
log(event)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
ExternalInterface.call(js);
|
||||
} catch (event:Error) {
|
||||
new log(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function openLink(url: String, target: String = '_blank', features: String = ""): void {
|
||||
var myURL: URLRequest = new URLRequest(url);
|
||||
//trace(url,myURL);
|
||||
try {
|
||||
ExternalInterface.call("window.open", url, target, features);
|
||||
} catch (event:Error) {
|
||||
try {
|
||||
ExternalInterface.call("function setWMWindow() {window.open('" + url + "', '" + target + "', '" + features + "');}");
|
||||
} catch (event: Error) {
|
||||
navigateToURL(myURL, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function getHttpKey(info: Object): Object {
|
||||
var k: String = "";
|
||||
var vf: Array = [],
|
||||
vt: Array = [];
|
||||
//script.traceObject(info);
|
||||
if (info.hasOwnProperty("keyframes")) {
|
||||
var keyframes: Object = info["keyframes"];
|
||||
for (k in keyframes) {
|
||||
switch (k) {
|
||||
case "times":
|
||||
vt.push(keyframes[k]);
|
||||
break;
|
||||
case "filepositions":
|
||||
vf.push(keyframes[k]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(keyframes.hasOwnProperty("filepositions") && keyframes["filepositions"]){
|
||||
vf=keyframes["filepositions"];
|
||||
}
|
||||
if(keyframes.hasOwnProperty("times") && keyframes["times"]){
|
||||
vt=keyframes["times"];
|
||||
}
|
||||
} else if (info.hasOwnProperty("seekpoints")) {
|
||||
var seekpoints: Object = info["seekpoints"];
|
||||
for (k in seekpoints) {
|
||||
var seekpoints2 = seekpoints[k];
|
||||
for (var k2: String in seekpoints2) {
|
||||
switch (k2) {
|
||||
case "time":
|
||||
vt.push(seekpoints2[k2]);
|
||||
break;
|
||||
case "offset":
|
||||
vf.push(seekpoints2[k2]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} //end for k2
|
||||
} //end for k
|
||||
}
|
||||
if (vt.length > 0) {
|
||||
info["keytime"] = vt;
|
||||
info["keyframes"] = vf;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
public static function randomString(len: int = 16): String { //获取一个随机值
|
||||
var chars: String = "abcdefghijklmnopqrstuvwxyz";
|
||||
var maxPos: int = chars.length;
|
||||
var val: String = "";
|
||||
for (var i: int = 0; i < len; i++) {
|
||||
val += chars.charAt(Math.floor(Math.random() * maxPos));
|
||||
}
|
||||
return 'ckv' + val;
|
||||
}
|
||||
public static function getPath(file: String): Object { //获取路径和对应ckplayer.swf的
|
||||
var p: String = file.split("?")[0];
|
||||
var a: Array = [];
|
||||
var g: String = "\/";
|
||||
var h: String = "";
|
||||
if (p.indexOf("\/") > -1) {
|
||||
a = p.split("\/");
|
||||
} else {
|
||||
a = p.split("/");
|
||||
g = "/";
|
||||
}
|
||||
for (var i: int = 0; i < a.length - 1; i++) {
|
||||
h += a[i] + g;
|
||||
}
|
||||
var fa: Array = a[a.length - 1].split("?");
|
||||
var xa: Array = fa[0].toString().split(".");
|
||||
return {
|
||||
path: h,
|
||||
file: fa[0],
|
||||
fileName: xa[0]
|
||||
};
|
||||
}
|
||||
public static function arrSum(arr: Array, sort: int = -1): Number { //将数组里的值相加,sort=指定截断
|
||||
var num: Number = 0;
|
||||
//trace(sort > 0 ? sort : arr.length);
|
||||
if (sort > arr.length || sort == -1) {
|
||||
sort = arr.length;
|
||||
}
|
||||
for (var i: int = 0; i < sort; i++) {
|
||||
num += Number(arr[i]);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
public static function replace(val: String, oldArr: Array, newArr: Array): String {
|
||||
if (!val || oldArr.length != newArr.length) {
|
||||
return val;
|
||||
}
|
||||
for (var i: int = 0; i < oldArr.length; i++) {
|
||||
val = val.split(oldArr[i]).join(newArr[i]);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
public static function getType(val: * ): String { //获取变量类型
|
||||
if (val == undefined) {
|
||||
return undefined
|
||||
}
|
||||
if (typeof (val) == "object") {
|
||||
if (val.length != undefined) {
|
||||
return "array";
|
||||
} else {
|
||||
return "object";
|
||||
}
|
||||
}
|
||||
return typeof (val);
|
||||
}
|
||||
public static function traceObject(cObj: Object): void { //输出对象和数组
|
||||
function tr(obj: Object, jg: String = "") {
|
||||
for (var k: String in obj) {
|
||||
//trace(jg, k, obj[k]);
|
||||
|
||||
if (typeof (obj[k]) == "object") {
|
||||
trace(jg, k, "{");
|
||||
tr(obj[k], jg + " ");
|
||||
trace(jg, "},");
|
||||
} else {
|
||||
if (typeof (obj[k]) == "string") {
|
||||
trace(jg, k, ":\"", obj[k], "\",");
|
||||
} else {
|
||||
trace(jg, k, ":", obj[k], ",");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
tr(cObj);
|
||||
}
|
||||
public static function strReplace(str: String, find: Array, replace: Array): String {
|
||||
if (str != "" && find.length == replace.length) {
|
||||
for (var i: int = 0; i < find.length; i++) {
|
||||
str = str.split(find[i]).join(replace[i]);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
public static function trackToArray(str: String):Array {
|
||||
var arr:Array=str.split(",");
|
||||
var tempArr:Array=[];
|
||||
var newArr:Array=[];
|
||||
for(var i=0;i<arr.length;i++){
|
||||
tempArr.push(arr[i]);
|
||||
if(i % 3==2){
|
||||
newArr.push(tempArr);
|
||||
tempArr=[];
|
||||
}
|
||||
}
|
||||
return newArr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package ckaction.act {
|
||||
import flash.utils.Timer;
|
||||
import flash.events.TimerEvent;
|
||||
|
||||
public class timeInterval {
|
||||
private var timer:Timer=null;
|
||||
private var success:Function=null;
|
||||
public function timeInterval(time:Number,fun:Function) {
|
||||
// constructor code
|
||||
success=fun;
|
||||
timer=new Timer(time)
|
||||
timer.addEventListener(TimerEvent.TIMER,timerHandler);
|
||||
}
|
||||
public function timerHandler(event:TimerEvent):void{
|
||||
//trace("正在运行计时器",success);
|
||||
success();
|
||||
}
|
||||
public function start():void{
|
||||
if(timer && !timer.running){
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
public function stop():void{
|
||||
if(timer && timer.running){
|
||||
timer.stop();
|
||||
}
|
||||
}
|
||||
public function close():void{
|
||||
if(timer){
|
||||
if(timer.running){
|
||||
timer.stop();
|
||||
}
|
||||
timer.removeEventListener(TimerEvent.TIMER,timerHandler);
|
||||
timer=null;
|
||||
}
|
||||
}
|
||||
public function running():Boolean{
|
||||
return timer.running;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package ckaction.act {
|
||||
import flash.events.TimerEvent;
|
||||
import flash.utils.Timer;
|
||||
|
||||
public class timeOut {
|
||||
private var timer: Timer = null;
|
||||
private var success: Function = null;
|
||||
private var parNum:int=-1;
|
||||
private var isStop:Boolean=false;
|
||||
public function timeOut(time: Number, fun: Function, num: int = -1) {
|
||||
// constructor code
|
||||
success = fun;
|
||||
parNum=num;
|
||||
timer = new Timer(time, 1);
|
||||
timer.addEventListener(TimerEvent.TIMER, timerHandler);
|
||||
timer.start();
|
||||
}
|
||||
private function timerHandler(event: TimerEvent): void {
|
||||
|
||||
if(isStop){
|
||||
return;
|
||||
}
|
||||
if(parNum>-1){
|
||||
success(parNum);
|
||||
}
|
||||
else{
|
||||
//trace("++",success);
|
||||
success();
|
||||
//trace("+---+",success);
|
||||
}
|
||||
stop();
|
||||
}
|
||||
public function stop():void{
|
||||
isStop=true;
|
||||
if (timer != null) {
|
||||
if (timer.running) {
|
||||
timer.stop();
|
||||
}
|
||||
timer.removeEventListener(TimerEvent.TIMER, timerHandler);
|
||||
timer = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user