月度存档: 8 月 2012

As3数组不改变顺序取最大值算法

[code] //取数组最大值
public static function getMax(arr:Array):* {
var a:Array=new Array();
a=arr.slice();
for (var i:int=0; i

As3事件传参数

方案一:
[code]// 要传递的参数
var value:int = 100;
// 触发事件的按钮
var btn:Btn = new Btn;
btn.addEventListener(MouseEvent.CLICK,clickHandler(value));

// 返回事件处理的函数
function clickHandler(v:int):Function
{
return function (e:MouseEvent):void{
//处理传入的参数 V
doSomeThing(v);
}
}
[/code]
方案二-代理类:
[code]
/**
*@author:Amyflash
* @example:
* import com.JEventDelegate
stage.addEventListener(MouseEvent.MOUSE_OVER,JEventDelegate.create(yourHandler,"t1","t2"));
function yourHandler(e:MouseEvent,…arg) {
trace(e)
trace(arg)
}
*/

package {
public class JEventDelegate {
public function JEventDelegate() {
}
public static function create(f:Function,…arg):Function {
var F:Boolean=false;
var _f:Function=function(e:*,…_arg){
_arg=arg
if(!F){
F=true
_arg.unshift(e)
}
f.apply(null,_arg)
};
return _f;
}
public static function toString():String {
return "Class JEventDelegate";
}
}
}
[/code]
方案三-扩展事件类

千分位数字格式化

package  
{
	/**
	 * ...
	 * @author harriet
	 */
	public class FormatValue 
	{
		
		public function FormatValue() 
		{
			
		}
		
		public static function format( 
            i:Number, 
            numDecimals:Number=0,
            isFixedNumDecimalsForced:Boolean=false, 
            isDecimalSeparatorComma:Boolean=false,
            isThousandSeparatorDisabled:Boolean=false 
        ) : String {
            if ( isNaN (numDecimals )) {
                numDecimals = 4;
            }
              
            if (isDecimalSeparatorComma) {
                var commaChar:String = '.';
                var decimalChar:String = ',';
            }
            else {
                commaChar = ',';
                decimalChar = '.';
            }
            if (isThousandSeparatorDisabled){
                commaChar = '';
            }
            // round the number down to the number of
            // decimals we want ( fixes the -1.11022302462516e-16 bug)
            i = Math.round(i*Math.pow(10,numDecimals))/Math.pow(10,numDecimals);
              
            var s:String = '';
            var num:Array;
            if( i<0 )
                num = String(-i).split('.');
            else
                num = String(i).split('.');
              
            //trace ("a: " + num[0] + ":" + num[1]);
            var x:String = num[0];
            var pos:Number=0;
            var c:Number=0;
            for(c=x.length-1;c>-1;c--)
            {
                if( pos%3==0 &&s.length>0 )
                {
                    s=commaChar+s;
                    pos=0;
                }
                pos++;
                      
                s=x.substr(c,1)+s;
            }
            if( num[1] != undefined ) {
                if (isFixedNumDecimalsForced){
                    num[1] += "0000000000000000";
                }
                s += decimalChar+ num[1].substr(0,numDecimals);
            } else {
                if (isFixedNumDecimalsForced && numDecimals>0){
                    num[1] = "0000000000000000";
                    s += decimalChar+ num[1].substr(0,numDecimals);         
                }
                  
            }
                  
            if( i<0 )
                s = '-'+s;
  
                return s;
        }
		
	}

}

As3的base64编码解码库

package com.dynamicflash.util{        
import flash.utils.ByteArray;             
public class Base64 {                    
  private static const BASE64_CHARS:String = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=”;  
          public static const version:String = “1.0.0”;  
          public static function encode(data:String):String {     
          // Convert string to ByteArray              
var bytes:ByteArray = new ByteArray();              
bytes.writeUTFBytes(data);                            
  // Return encoded ByteArray              
return encodeByteArray(bytes);          
}                     
public static function encodeByteArray(data:ByteArray):String
{               // Initialise output              
var output:String = “”;                             
// Create data and output buffers              
var dataBuffer:Array;              
var outputBuffer:Array = new Array(4);                              // Rewind ByteArray               data.position = 0;                              // while there are still bytes to be processed               while (data.bytesAvailable > 0) {                   // Create new data buffer and populate next 3 bytes from data                   dataBuffer = new Array();        
           for (var i:uint = 0; i < 3 && data.bytesAvailable > 0; i++) {                       dataBuffer[i] = data.readUnsignedByte();                   }                                      // Convert to data buffer Base64 character positions and                    // store in output buffer                   outputBuffer[0] = (dataBuffer[0] & 0xfc) >> 2;               
    outputBuffer[1] = ((dataBuffer[0] & 0x03) << 4) | ((dataBuffer[1]) >> 4);                   outputBuffer[2] = ((dataBuffer[1] & 0x0f) << 2) | ((dataBuffer[2]) >> 6);                   outputBuffer[3] = dataBuffer[2] & 0x3f;    
                                  // If data buffer was short (i.e not 3 characters) then set                   // end character indexes in data buffer to index of ‘=’ symbol.          
         // This is necessary because Base64 data is always a multiple of  
                // 4 bytes and is basses with ‘=’ symbols.                 
  for (var j:uint = dataBuffer.length; j < 3; j++) {                        outputBuffer[j + 1] = 64;                   }                                       // Loop through output buffer and add Base64 characters to                    // encoded data string for each character.                   for (var k:uint = 0; k < outputBuffer.length; k++) {                        output += BASE64_CHARS.charAt(outputBuffer[k]);                   }               }                               // Return encoded data               return output;           }                       SNG-demonsu(1373211) 15:33:24  public static function decode(data:String):String {               // Decode data to ByteArray                var bytes:ByteArray = decodeToByteArray(data);                               // Convert to string and return                return bytes.readUTFBytes(bytes.length);            }                       public static function decodeToByteArray(data:String):ByteArray {                // Initialise output ByteArray for decoded data                var output:ByteArray = new ByteArray();                               // Create data and output buffers                var dataBuffer:Array = new Array(4);               var outputBuffer:Array = new Array(3);                 // While there are data bytes left to be processed                for (var i:uint = 0; i < data.length; i += 4) {                    // Populate data buffer with position of Base64 characters for                    // next 4 bytes from encoded data                   for (var j:uint = 0; j < 4 && i + j < data.length; j++) {                        dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt(i + j));                   }                                       // Decode data buffer back into bytes                    outputBuffer[0] = (dataBuffer[0] << 2) + ((dataBuffer[1] & 0x30) >> 4);                  
outputBuffer[1] = ((dataBuffer[1] & 0x0f) << 4) + ((dataBuffer[2] & 0x3c) >> 2);                          
outputBuffer[2] = ((dataBuffer[2] & 0x03) << 6) + dataBuffer[3];                                      // Add all non-padded bytes in output buffer to decoded data                    for (var k:uint = 0; k < outputBuffer.length; k++) {                       if (dataBuffer[k+1] == 64) break;                        output.writeByte(outputBuffer[k]);                   }               }                               // Rewind decoded data ByteArray               output.position = 0;                              // Return decoded data               return output;            }                       public function Base64() {                throw new Error("Base64 class is static container only");           }     } }

wp自动post

$title,
‘description’=>$body,
‘mt_allow_comments’=>0, // 1 to allow comments
‘mt_allow_pings’=>0, // 1 to allow trackbacks
‘post_type’=>’post’,
‘mt_keywords’=>$keywords,
‘categories’=>array($category)
);

//这块一定要加,解决中文乱码问题
$output_options = array(“output_type” => “xml”,”verbosity” => “pretty”,”escaping” => array(“markup”),”version” => “xmlrpc”,”encoding” => “utf-8”);

$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request(‘metaWeblog.newPost’,$params,$output_options);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
}

>

flashplayer11.4来临mark并发功能测试

9ria动作好快,翻译版都出来了,哇哈哈

http://esdot.ca/site/2012/intro-to-as3-workers-part-2-image-processing
译文:
http://blog.domlib.com/articles/326

Yellow-JEM 这歌不错,mark

Look at the stars 仰望天上的星星
Look how they shine for you 看着它们为你绽放光芒
And everything you do
Yeah, they were all yellow 而你却如此胆怯小心

I came along 跟随着你
I wrote a song for you 我为你写下了一首情歌
And all the things you do 因为你表现出的胆怯小心
And it was called yellow 歌名叫做”黄色”

So then I took my turn 我会全心全意
Oh what a thing to have done 想突破你的心房赢得你的芳心
And it was all yellow 却也担心害怕起来

Your skin, oh yeah your skin and bones 你的肌肤
Turn into something beautiful 是如此的美丽脱俗而真实
D’you know? 你该知道
You know I love you so 我不可自拔的爱上了你
You know I love you so 你该明了我已经深深地爱上了你

I swam across 整个心早已游向你
I jumped across for you 整个人急着想飞奔到你面前却又却步
Oh what a thing to do 不知如何靠近你
‘Cos you were all yellow 因为你是如此胆怯小心

I drew a line 我画出你的肖像
I drew a line for you 我画下了你的样子
Oh what a thing to do 却不知该如何表示
And it was all yellow 因为你是如此胆怯小心

And your skin, oh yeah your skin and bones 你的肌肤
Turn into something beautiful 是如此美丽脱俗而真实
D’you know? 你该知道
For you I bleed myself dry 我愿为你抛开一切
For you I bleed myself dry 你该明了,我为你失去生命也不可惜

It’s true 这是真的
Look how they shine for you 星星都因为你绽放光芒
Look how they shine for you 星星都因为你绽放光芒
Look how they shine for you 看!它们都为你绽放光芒
Look how they shine for you 看!它们都为你绽放光芒
Look how they shine for you 星星都因为你绽放光芒
Look how they shine

Look at the stars 仰望天上的星星
Look how they shine for you 看着它们为你绽放光芒
And all the things that you do 而你却如此胆怯小心

as3获取加载进来的swf的类

var swfTarget:LoaderInfo=event.target as LoaderInfo;

//swfTarget的只读属性applicationDomain返回一个ApplicationDomain

//创建被加载swf的应用程序域

var appDomain:ApplicationDomain=swfTarget.applicationDomain as ApplicationDomain;

//getDefinition方法从指定的应用程序域获取一个公共定义。

//该定义可以是一个类、一个命名空间或一个函数的定义。

//其中”myClass”为被加载swf文件里影片剪辑链接属性里的类

var jsClass:Class=appDomain.getDefinition(“JsonStatic”) as Class;

ComboBox组件的使用

import fl.controls.ComboBox;
var _combox:ComboBox = new ComboBox();
_combox.addItem({label:"腾讯",data:12});
_combox.addItem( { label:"新浪", data:11 } );
_combox.addItem({label:"网易",data:13});
_combox.addItem({label:"总共",data:36});
_combox.x = 100
_combox.y = 10;
_combox.rowCount =10;
addChild(_combox);

var tf:TextFormat= new TextFormat();
tf.color = 0x00ffff;
tf.font = "宋体";
tf.size = 12;
//设置下拉框默认字体
_combox.textField.setStyle("textFormat",tf);
//设置下拉框List字体;
_combox.dropdown.setRendererStyle("textFormat",tf);
//ComboBox的实例名为selectBox,添加侦听;
_combox.addEventListener(Event.CHANGE, cbListener);
function cbListener(e:Event):void
{

trace(ComboBox(e.target).selectedItem.data);

}

can’t convert Fixnum into String

运行rake db:migrate时报上述错误:can’t convert Fixnum into String

是由于将数据库密码写成了数字导致,只需将config/database.yml中

password: 123456 改成 password:”123456″即可。