月度存档: 3 月 2014

flashdevelop嵌入字体

package 
{
    import flash.text.*;
    import flash.display.MovieClip;
    public class FontClass extends MovieClip 
    {            
     [Embed(source="Arial Bold.ttf", fontName="myFont", embedAsCFF = "false",fontWeight="bold", advancedAntiAliasing="true", mimeType="application/x-font")]
     private var theClass:Class;
     public function FontClass ()
     { 
            var t:TextField=new TextField();
            t.embedFonts = true; 
            var textFormat:TextFormat=new  TextFormat();
            textFormat.size = "30";
            textFormat.font = "myFont";
            t.text = "[Embed] metadata rocks!!!";
            t.width = 500;
            t.setTextFormat (textFormat); 
            addChild (t);  
     } 
    } 
}
[Embed(systemFont="Letter Gothic Std",embedAsCFF = "false", fontName = 'lgsbFont', fontWeight="bold", advancedAntiAliasing="true", mimeType="application/x-font",unicodeRange="U+0000-U+007F")] private static var ArialFont: Class; var textFormat: TextFormat = new TextFormat("ArialRegular", 50, 0x0000FF); text1 = new TextField(); text1.embedFonts = true; text1.defaultTextFormat = textFormat; text1.autoSize = "left"; text1.text = "Thanh";

锚点定位

今天一个美术同事问我,页面上的flash按钮点击跳转到页面锚点怎么实现,要求用as2写,虽然我多年不写as2了,但是照顾美术同事,找了相关资料,捣腾出代码如下:

flash里代码:

import flash.external.*;
var urlPath = ExternalInterface.call('eval', 'window.location.href');
btn.onRelease = function(){
	getURL(urlPath+"#firstAnchor");
	}

页面上添加锚点firstAnchor看效果罗

php解压swf

<?php  
//文件名
$filename = "test.swf";
//打开文件
$rs = fopen($filename,"r");
//读取文件的数据
$str = fread($rs,filesize($filename));
//check compress status
$check = substr($str,0,1);
if($check=="C")
{
	echo "这是一个压缩文件,下面解压";
//设置swf头文件
$head = substr($str,1,7);
$head = "F".$head;
//获取swf文件内容
$body = substr($str,8);
//解压缩文件内容
$body = gzuncompress($body);
//合并文件头和内容
$str = $head.$body;
//关闭读取的文件流
fclose($rs);
//创建一个新的文件
$ws = fopen("jieya.swf","w");
//写文件
fwrite($ws,$str);
}else if($check=="F")
{
	echo "这是一个没有压缩的文件,下面开始压缩";
	$head = substr($str,1,7);
$head = "C".$head; 
$body = substr($str,8); 
$body = gzcompress($body, 9);  
$str = $head.$body; 
fclose($rs);  
$ws = fopen("yasuo.swf","w");  
fwrite($ws,$str);  
}else
{
  echo "这不是一个合法的flash文件";
}
//关闭文件
fclose($ws);
?>

php通过ming扩展创建swf经典范例

1.画个正方形

<?php
$mc = new SWFMovie();
$mc->setDimension( 200, 200 );

$s = new SWFShape();
$s->setLine( 5, 0, 0, 0 );
$s->movePenTo( 20, 20 );
$s->drawLineTo( 160, 20 );
$s->drawLineTo( 160, 160 );
$s->drawLineTo( 20, 160 );
$s->drawLineTo( 20, 20 );
$mc->add( $s );
$mc->save( 'shape.swf' );
?>

2.合并jpg图片

<?php
   $m = new SWFMovie();
  $m->setDimension(200, 200);
  $m->add(new SWFBitmap(fopen("s.jpg", "rb")));

  //header('Content-type: application/x-shockwave-flash');
  $m->save( 'shape4.swf' );
?>

3.外部加载swf

<?php
    $m = new SWFMovie();
    $m->setRate(30.000000);
    $m->setDimension(200, 200);
    $m->setBackground(0xff, 0xff, 0xff);

    $m->add(new SWFAction('
        myvar = "variable to pass to flash";
        LoadMovie("shape4.swf", "mc");
    '));

    /* -- make movie clip 'mc' that we will load flash_file_created_by_hand.swf into -- */
    $s1 = new SWFSprite();  /* (1 frames) */
    $s1->nextFrame();  /* (end of sprite frame 0) */
    $i1 = $m->add($s1);
    $i1->setName('mc');
    $m->nextFrame();  /* (end of frame 0) */

    //header('Content-type: application/x-shockwave-flash');
   // $m->output();
   $m->save("1.swf");
?>

4.合并swf,(注意这里的swf都是非压缩的,要合并压缩的swf,先要解压缩然后再压缩,参考这篇文章:php解压swf)

<?php
   $m = new SWFMovie();
  $m->setDimension(200, 200);
  $m->add(new SWFPrebuiltClip(fopen("shape4.swf", "rb")));
  $m->add(new SWFPrebuiltClip(fopen("shape.swf", "rb")));
  //header('Content-type: application/x-shockwave-flash');
  $m->save( 'ms.swf' );
?>

Ubuntu设置环境变量并立即生效

Ubuntu Linux系统包含两类环境变量:系统环境变量和用户环境变量。系统环境变量对所有系统用户都有效,用户环境变量仅仅对当前的用户有效。

修改用户环境变量

用户环境变量通常被存储在下面的文件中:

  • ~/.profile
  • ~/.bash_profile 或者 ~./bash_login
  • ~/.bashrc

上述文件在Ubuntu 10.0以前版本不推荐使用。

系统环境变量

系统环境变量一般保存在下面的文件中:

  • /etc/environment
  • /etc/profile
  • /etc/bash.bashrc

/etc/profile和 /etc/bash.bashrc在Ubuntu 10.0版本中不推荐使用。

加入环境变量

如想将一个路径加入到$PATH中,可以像下面这样做(修改/etc/profile):

1
sudo nano /etc/profile

在里面加入:

1
2
3
4
5
6
JAVA_HOME=/usr/jdk1.6.0_25
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
CLASSPATH=.:$JAVA_HOME/lib
export CLASSPATH

你可以自己加上指定的多个路径,中间用冒号隔开。环境变量更改后,在用户下次登陆时生效,如果想立刻生效,则可执行下面的语句:

1
$source /etc/profile

需要注意的是,最好不要把当前路径”./”放到PATH里,这样可能会受到意想不到的攻击。

其他文件的修改方式与此类似,需要注意的是/etc/environment不需要使用export设置环境变量,其他profile文件需要。

更详细的说明可以参考这里

当然如果想使用文本编辑工具修改环境变量,可以使用root权限登录后,直接用文本编辑器打开修改保存

也可以普通用户权限下把文件复制到桌面等修改后用root权限覆盖回去

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
 # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
    
 if [ -d /etc/profile.d ]; then
   for i in /etc/profile.d/*.sh; do
     if [ -r $i ]; then
       . $i
     fi
   done
    
 JAVA_HOME=/usr/hadoop/jdk1.6.0_25
 export JAVA_HOME
 PATH=$PATH:$JAVA_HOME/bin
 export PATH
 CLASSPATH=.:$JAVA_HOME/lib
 export CLASSPATH
    
   unset i
 fi
    
 if [ "$PS1" ]; then
   if [ "$BASH" ]; then
     # The file bash.bashrc already sets the default PS1.
     # PS1='\h:\w\$ '
     if [ -f /etc/bash.bashrc ]; then
       . /etc/bash.bashrc
     fi
   else
     if [ "`id -u`" -eq 0 ]; then
       PS1='# '
     else
       PS1='$ '
     fi
   fi
 fi

How to Install C and C++ Compilers in Ubuntu and testing your first C and C++ Program

If you are a developer you need C and C++ Compiler for your development work.In ubuntu you can install the build-essential for C and C++ compilers.
Install C and C++ Compilers in Ubuntu:
[code]sudo aptitude install build-essential[/code]
This will install all the required packages for C and C++ compilers
Testing C and C++ Programs

Compiling Your first C Programs

Now you need to open first.c file

sudo gedit first.c

add the following lines save and exit the file

[code]
#include<stdio.h>
int main(){
printf("hello,world\n");
return 0;
}
[/code]

Firstly compile the code using the following command

cc -c first.c

that would produce an object file you may need to add to the library.

then create an executable using the following command

cc -o first first.c

Now run this executable using the following command

./first

Output should show as follows

Hello, world

Compiling your first C++ program

If you want to run c++ program follow this procedure

g++ is the compiler that you must use.

you should use a .cpp file extension rather than a .c one

You need to create a file

sudo gedit first.cpp

add the following lines save and exit the file

[code]
#include<iostream>
int main(){
std::cout<<"Hello World!" <<std::endl;
return 0;
}
[/code]

Run your C++ Program using the following command

g++ first.cpp -o test

./test

Output should show as follows

Hello World!

如何让php的json_encode不转义反斜杠

解决办法:

1. 正则替换

echo str_replace(“\\/”, “/”, json_encode(“2013/4/21”));
2. 若是php版本是5.4的话:

echo json_encode(“2011/7/11”, JSON_UNESCAPED_SLASHES);

Jangaroo等宽高瀑布流算法

[code]
//data.json
{
"items": [{
"img_url": "imgs/anjuke.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/yile.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/ctrip.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/lifevc.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/xdf.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/taoche.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}, {
"img_url": "imgs/fanke.png",
"link_url": "http://www.amyflash.com",
"intro": "it is a message"
}

]

}
[/code]

package com.acme.jooflash
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;

	import joo.getQualifiedObject;
	import js.Document;

	/**
	 * ...
	 * @author harriet
	 */
	[SWF( backgroundColor='0xFFFFFF', frameRate='30', width='640', height='480')]
	public class Main extends Sprite 
	{
		private var sw:Number = 800;
		private var sh:Number = 700;

		private var dataloader:URLLoader = new URLLoader();
		private var count:Number = 0;

		private var top:int = 100;
		private var left:int = 100;

		public function Main() 
		{
			if (ExternalInterface.available) {
				sw = ExternalInterface.call("getw");
				sh = ExternalInterface.call("geth");
			}

			this.stage.stageWidth = sw;
			this.stage.stageHeight = sh;

			var surl:String = "data.json";
			var surlr:URLRequest = new URLRequest(surl);
			dataloader.load(surlr);
			dataloader.addEventListener(Event.COMPLETE, getData);

		}

		private function getData(e:Event):void
		{
			 var sMyString:String = dataloader.data;
			 var t:Object = window['JSON'].parse(sMyString);
			 count = t.items.length;

			for each(var item in t.items )
			{

				var url:String = item.img_url;

				var urlr:URLRequest = new URLRequest(url);
				var loader:Loader = new Loader();
				loader.load(urlr);
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, doShow);
			}
		}

		private var right:Number;

		private var viewi:int = 0;
		private var pviewi:int = 0;
		private var dx:int = 10;
		private var dy:int = 10;
		private var pline:int = -1;
		private function doShow(e:Event):void
		{

			var t:DisplayObject = (e.target.loader as Loader).content;
			 right = sw - left - t.width;
			addChild(t);

			t.x = left + (t.width + dx) * viewi++;
			t.y = top;
			if (t.x > right)
			{
				if(pline==-1)
				{
					pline = viewi-1;
					trace(pline);//求出多少列
				}

				pviewi = viewi-1;
				if (pline != 0)
				{
					t.y = top+Math.floor(pviewi / pline) * (t.height + dy);
					t.x = left + (t.width + dx) * (pviewi % pline);
				}else
				{
					t.x = 5;
					t.y = 5 + pviewi * (t.height + dy);
				}	
			}

		}

	}
}

jangaroo中xml的处理

//sMyString为加载到的字符串

/*handle xml
			 * var DOMParser:Class = getQualifiedObject('DOMParser');
				  if (DOMParser) {
					var oDOM:Document = new DOMParser().parseFromString(sMyString, "text/xml");
				  } else {
					var ActiveXObject:Class = getQualifiedObject('ActiveXObject');
					if (!ActiveXObject) {
					  throw new Error("No XML support!");
					}
					oDOM = new ActiveXObject("Microsoft.XMLDOM");
					oDOM['async'] = "false";
					oDOM['loadXML'](sMyString);
				  }
		  // print the name of the root element or error message
		  trace(oDOM.documentElement.nodeName == "parsererror" ? "error while parsing" : oDOM.documentElement.nodeName);*/

Jangaroo自适应浏览器宽高

as代码:

package com.acme.jooflash
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.text.TextField;

	/**
	 * ...
	 * @author harriet amyflash.com

	 */
	[SWF( backgroundColor='0xFFFFFF', frameRate='30', width='640', height='480')]
	public class Main extends Sprite 
	{
		private var sw:Number = 800;
		private var sh:Number = 700;

		public function Main() 
		{
			/*var helloWorld:TextField = new TextField();
			helloWorld.text = "Hello Harriet!";
			addChild(helloWorld);*/

			/*var s:Sprite = new Sprite();
			s.graphics.beginFill(0xff00ff, 0.1);
			s.graphics.drawCircle(100, 0, 100);
			s.graphics.endFill();
			addChild(s);
			s.addEventListener(MouseEvent.MOUSE_OVER, doClick);*/

			if (ExternalInterface.available) {
				sw = ExternalInterface.call("getw");
				sh = ExternalInterface.call("geth");
			}

			this.stage.stageWidth = sw;
			this.stage.stageHeight = sh;

			var url:String = "logo.png";
			var urlr:URLRequest = new URLRequest(url);

			loader.load(urlr);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, doShow);
			//addChild(loader);
		}

		private var loader:Loader = new Loader();
		private function doShow(e:Event):void
		{
			var t:DisplayObject = loader.content;
                       //(e.target.loader as Loader).content--加载多个图片有用
			 addChild(t); 

			 t.x = (sw - t.width) / 2;
			 t.y = (sh - t.height) / 2;
		}
	}
}

首页index.html

<!DOCTYPE html>
<html>
<head>
  <title>t2</title>
  <script>
  //获取浏览器窗口宽高
var winWidth = 0; 
var winHeight = 0; 

function findDimensions() //函数:获取尺寸 
{ 
//获取窗口宽度 
if (window.innerWidth) 
winWidth = window.innerWidth; 
else if ((document.body) && (document.body.clientWidth)) 
winWidth = document.body.clientWidth; 
//获取窗口高度 
if (window.innerHeight) 
winHeight = window.innerHeight; 
else if ((document.body) && (document.body.clientHeight)) 
winHeight = document.body.clientHeight; 
//通过深入Document内部对body进行检测,获取窗口大小 
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) 
{ 
winHeight = document.documentElement.clientHeight; 
winWidth = document.documentElement.clientWidth; 
} 

} 

 findDimensions();
//设置iframe宽高
function reSetWH(obj)
{  
	findDimensions();
    obj.width = winWidth;
    obj.height = winHeight;

	console.log(winWidth+","+winHeight);
}

//告诉as舞台宽高
function getw(){
return winWidth;
}

function geth(){
return winHeight;
}

function reSetIframe()
{
	location.reload(); //刷新页面
}

</script>

</head>
<body onresize="reSetIframe();">
<!--h1>t2</h1-->

<iframe id="stage" src="jooflash.html" frameborder="0" width="640" height="480" onload="reSetWH(this);" >
  no frames
</iframe>
</body>
</html>