Jul
25
package Bearbox.Loading
{
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;
public class MyLoading extends DownloadProgressBar
{
private var _preloader:Sprite;
private var logo:Loader = new Loader();
private var loadingBar:Shape = new Shape();
private var txt:TextField = new TextField();
public function MyLoading()
{
// logo
logo.load(new URLRequest("http://www.dv9.org/images/logo.gif"));
addChild(logo);
// loading bar
addChild(loadingBar);
// txt
var style:TextFormat = new TextFormat(null, null, 0xFFFFFF, null, null, null, null, null, "center");
txt.defaultTextFormat = style;
txt.selectable = false;
txt.width = 200;
txt.height = 50;
addChild(txt);
super();
}
override public function set preloader(value:Sprite):void
{
_preloader = value;
_preloader.contextMenu = MyContextMenu.getMyContextNenu();
//四个侦听~分别是加载进度 / 加载完毕 / 初始化进度 / 初始化完毕
_preloader.addEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
_preloader.addEventListener(Event.COMPLETE, loadCompleteHandler);
_preloader.addEventListener(FlexEvent.INIT_PROGRESS, loadInitProgressHandler);
_preloader.addEventListener(FlexEvent.INIT_COMPLETE, loadInitCompleteHandler);
stage.addEventListener(Event.RESIZE, resizeHandler);
resizeHandler(null);
}
private function loadProgressHandler(event:ProgressEvent):void
{
var ratio:Number = event.bytesLoaded/event.bytesTotal;
// loading bar
loadingBar.graphics.clear();
loadingBar.graphics.beginFill(Math.random() * 0xFFFFFF);
loadingBar.graphics.drawRect(0,0, ratio*128, 5);
loadingBar.graphics.endFill();
// txt
txt.text = "Dv9.Org� 载中 " + ((ratio*100)>>0) + "%";
}
private function loadCompleteHandler(event:Event):void
{
txt.text = "Dv9.Org加载成功!";
}
private function loadInitProgressHandler(event:FlexEvent):void
{
txt.text = "Dv9.Org加载中!";
}
private function loadInitCompleteHandler(event:FlexEvent):void
{
txt.text = "Dv9.Org加载中成功!";
_preloader.removeEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
_preloader.removeEventListener(Event.COMPLETE, loadCompleteHandler);
_preloader.removeEventListener(FlexEvent.INIT_PROGRESS, loadInitProgressHandler);
_preloader.removeEventListener(FlexEvent.INIT_COMPLETE, loadInitCompleteHandler);
stage.removeEventListener(Event.RESIZE, resizeHandler);
//最后这个地方需要dpepatch一个Event.COMPLETE事件..表示� 载完毕让swf继续操作~
dispatchEvent(new Event(Event.COMPLETE));
}
private function resizeHandler(event:Event):void
{
logo.x = (stage.stageWidth-128) * .5;
logo.y = (stage.stageHeight-185) *.5;
loadingBar.x = (stage.stageWidth-128) * .5;
loadingBar.y = (stage.stageHeight-185) *.5 + 128;
txt.x = (stage.stageWidth-200) * .5;
txt.y = (stage.stageHeight-185) *.5 + 135;
graphics.clear();
graphics.beginFill(0x333333);
graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
graphics.endFill();
}
}
}
{
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;
public class MyLoading extends DownloadProgressBar
{
private var _preloader:Sprite;
private var logo:Loader = new Loader();
private var loadingBar:Shape = new Shape();
private var txt:TextField = new TextField();
public function MyLoading()
{
// logo
logo.load(new URLRequest("http://www.dv9.org/images/logo.gif"));
addChild(logo);
// loading bar
addChild(loadingBar);
// txt
var style:TextFormat = new TextFormat(null, null, 0xFFFFFF, null, null, null, null, null, "center");
txt.defaultTextFormat = style;
txt.selectable = false;
txt.width = 200;
txt.height = 50;
addChild(txt);
super();
}
override public function set preloader(value:Sprite):void
{
_preloader = value;
_preloader.contextMenu = MyContextMenu.getMyContextNenu();
//四个侦听~分别是加载进度 / 加载完毕 / 初始化进度 / 初始化完毕
_preloader.addEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
_preloader.addEventListener(Event.COMPLETE, loadCompleteHandler);
_preloader.addEventListener(FlexEvent.INIT_PROGRESS, loadInitProgressHandler);
_preloader.addEventListener(FlexEvent.INIT_COMPLETE, loadInitCompleteHandler);
stage.addEventListener(Event.RESIZE, resizeHandler);
resizeHandler(null);
}
private function loadProgressHandler(event:ProgressEvent):void
{
var ratio:Number = event.bytesLoaded/event.bytesTotal;
// loading bar
loadingBar.graphics.clear();
loadingBar.graphics.beginFill(Math.random() * 0xFFFFFF);
loadingBar.graphics.drawRect(0,0, ratio*128, 5);
loadingBar.graphics.endFill();
// txt
txt.text = "Dv9.Org� 载中 " + ((ratio*100)>>0) + "%";
}
private function loadCompleteHandler(event:Event):void
{
txt.text = "Dv9.Org加载成功!";
}
private function loadInitProgressHandler(event:FlexEvent):void
{
txt.text = "Dv9.Org加载中!";
}
private function loadInitCompleteHandler(event:FlexEvent):void
{
txt.text = "Dv9.Org加载中成功!";
_preloader.removeEventListener(ProgressEvent.PROGRESS, loadProgressHandler);
_preloader.removeEventListener(Event.COMPLETE, loadCompleteHandler);
_preloader.removeEventListener(FlexEvent.INIT_PROGRESS, loadInitProgressHandler);
_preloader.removeEventListener(FlexEvent.INIT_COMPLETE, loadInitCompleteHandler);
stage.removeEventListener(Event.RESIZE, resizeHandler);
//最后这个地方需要dpepatch一个Event.COMPLETE事件..表示� 载完毕让swf继续操作~
dispatchEvent(new Event(Event.COMPLETE));
}
private function resizeHandler(event:Event):void
{
logo.x = (stage.stageWidth-128) * .5;
logo.y = (stage.stageHeight-185) *.5;
loadingBar.x = (stage.stageWidth-128) * .5;
loadingBar.y = (stage.stageHeight-185) *.5 + 128;
txt.x = (stage.stageWidth-200) * .5;
txt.y = (stage.stageHeight-185) *.5 + 135;
graphics.clear();
graphics.beginFill(0x333333);
graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
graphics.endFill();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
preloader="Bearbox.Loading" creationComplete="init()">
<mx:Script>
<![CDATA[
private function init():void
{
this.contextMenu = MyContextMenu.getMyContextNenu();
}
]]>
</mx:Script>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
preloader="Bearbox.Loading" creationComplete="init()">
<mx:Script>
<![CDATA[
private function init():void
{
this.contextMenu = MyContextMenu.getMyContextNenu();
}
]]>
</mx:Script>
</mx:Application>
Jul
25
问题出在 this.addChild( e.target.content );经过测试发现,当loader成功,而不将loader进来的对象 入显示列表的时候就会报错
所以正确代 如下
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
public class test1 extends MovieClip
{
private var _loader:Loader
public function test1()
{
this._loader = new Loader()
this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete)
this._loader.load( new URLRequest("flexTest.swf"))
}
private function onComplete(e:Event):void
{
this.addChild( e.target.content );
}
}
}
所以正确代 如下
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
public class test1 extends MovieClip
{
private var _loader:Loader
public function test1()
{
this._loader = new Loader()
this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete)
this._loader.load( new URLRequest("flexTest.swf"))
}
private function onComplete(e:Event):void
{
this.addChild( e.target.content );
}
}
}
Jul
25
近日做了个Flash无缝滚动图片展示效果,用来解决现在网站中JS图片滚动效果的不兼容问题。
暂时命名为BearBox Flash 图片无缝滚动 V1.0版好了,还有预想的部分功能没有加入。
BearBox Flash 图片无缝滚动 V1.0版本实现功能:
1,不间断向上滚动(可向下向左向右,将在2.0版本中加入动态设置滚动的方向)
2,鼠标悬浮停止滚动,移开继续滚动
3,动态加载XML,动态设置限制加载图片的多少(在1.0版本默认为6张,多加入几张的话还需改代码,2.0中将动态设置)
Flash Player文件
一直都拿不出那份闲心来搞这东西,今天更新了下,算做是1.5版本吧
代码就这些了 XML如下
开始竟然没放出源码 汗
下载文件
暂时命名为BearBox Flash 图片无缝滚动 V1.0版好了,还有预想的部分功能没有加入。
BearBox Flash 图片无缝滚动 V1.0版本实现功能:
1,不间断向上滚动(可向下向左向右,将在2.0版本中加入动态设置滚动的方向)
2,鼠标悬浮停止滚动,移开继续滚动
3,动态加载XML,动态设置限制加载图片的多少(在1.0版本默认为6张,多加入几张的话还需改代码,2.0中将动态设置)
Flash Player文件一直都拿不出那份闲心来搞这东西,今天更新了下,算做是1.5版本吧
stop();
System.useCodePage=true;
XML.ignoreWhitespace=true;
var loading:Loading;
var bb:int;
var bbb:int;
var BearXML:XML;
var myContextMenu:ContextMenu = new ContextMenu();
myContextMenu.hideBuiltInItems();
var item:ContextMenuItem=new ContextMenuItem("DV9.ORG");
myContextMenu.customItems.push(item);
this.contextMenu=myContextMenu;
loading=new Loading();
addChild(loading);
var BearPic:Sprite = new Sprite();
addChild(BearPic);
var BearPic1:Sprite = new Sprite();
addChild(BearPic1);
loading.x=(stage.stageWidth-loading.width)/2;
loading.y=(stage.stageHeight-loading.height)/3;
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("/list.aspx?colid=33"));
loader.addEventListener(Event.COMPLETE,loader_onComplete);
function loader_onComplete(e:Event):void{
removeChild(loading);
var BearXML:XML = XML(e.target.data);
var total:Number = 0;
bbb=BearXML.xxx.length();
bb=bbb*180;
for (var j:uint=0; j< BearXML.xxx.length(); j++) {
var bpp:bp=new bp;
bpp.pic.source=BearXML.xxx.path[j];
bpp.t.text=BearXML.xxx.span[j];
bpp.x=180*j;
bpp.y=5;
bpp.name="bear"+j;
BearPic.addChild(bpp);
BearPic.x=10;
BearPic.y=5;
var bpx:bp=new bp;
bpx.pic.source=BearXML.xxx.path[j];
bpx.t.text=BearXML.xxx.span[j];
bpx.x=180*j;
bpx.y=5;
bpx.name="n"+j;
BearPic1.addChild(bpx);
BearPic1.x=659;
BearPic1.y=5;
}
if(bbb>3){
myTimer.start();
}else {
trace("图片未超过3张不滚动");
}
}
var i=0;
var t=0;
var z=0;
var isMov:Boolean=true;
var myTimer:Timer=new Timer(10,0);
myTimer.addEventListener(TimerEvent.TIMER,timeFun);
function timeFun(evt:TimerEvent):void {
if(isMov){
BearPic.x -= 1;
i++
}
//trace("一:"+i);
if(i > bb-640){
myTimer1.addEventListener(TimerEvent.TIMER,T2);
myTimer1.start();
}
if(i > bb){
BearPic.x=659;
myTimer.removeEventListener(TimerEvent.TIMER,timeFun);
i=0;
//trace("一:归档------------------------------------------");
}
}
var myTimer1:Timer=new Timer(10,0);
myTimer1.addEventListener(TimerEvent.TIMER,T2);
function T2(eve:Event):void{
var DV9:int=(bbb-3)*180+540;
if(isMov){
BearPic1.x -= 1;
t++
}
//trace("二:"+t);
if(t > bb*2-DV9){
myTimer2.addEventListener(TimerEvent.TIMER,T3);
myTimer2.start();
}
if(t > bb+659){
BearPic1.x=659;
myTimer1.removeEventListener(TimerEvent.TIMER,T2);
t=0;
//trace("二:归档------------------------------------------");
}
}
var myTimer2:Timer=new Timer(10,0);
myTimer2.addEventListener(TimerEvent.TIMER,T3);
function T3(eve:Event):void{
var ORG:int=(bbb-3)*180+530;
if(isMov){
BearPic.x -= 1;
z++
}
//trace("二:"+t);
if(z > bb*2-ORG){
myTimer1.addEventListener(TimerEvent.TIMER,T2);
myTimer1.start();
}
if(z > bb+659){
BearPic.x=659;
myTimer2.removeEventListener(TimerEvent.TIMER,T3);
z=0;
//trace("二:归档------------------------------------------");
}
}
function OVER(e:Event) {
isMov=false;
}
function OUT(e:Event) {
isMov=true;
}
BearPic.addEventListener(MouseEvent.MOUSE_OVER,OVER);
BearPic.addEventListener(MouseEvent.MOUSE_OUT,OUT);
BearPic1.addEventListener(MouseEvent.MOUSE_OVER,OVER);
BearPic1.addEventListener(MouseEvent.MOUSE_OUT,OUT);
System.useCodePage=true;
XML.ignoreWhitespace=true;
var loading:Loading;
var bb:int;
var bbb:int;
var BearXML:XML;
var myContextMenu:ContextMenu = new ContextMenu();
myContextMenu.hideBuiltInItems();
var item:ContextMenuItem=new ContextMenuItem("DV9.ORG");
myContextMenu.customItems.push(item);
this.contextMenu=myContextMenu;
loading=new Loading();
addChild(loading);
var BearPic:Sprite = new Sprite();
addChild(BearPic);
var BearPic1:Sprite = new Sprite();
addChild(BearPic1);
loading.x=(stage.stageWidth-loading.width)/2;
loading.y=(stage.stageHeight-loading.height)/3;
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("/list.aspx?colid=33"));
loader.addEventListener(Event.COMPLETE,loader_onComplete);
function loader_onComplete(e:Event):void{
removeChild(loading);
var BearXML:XML = XML(e.target.data);
var total:Number = 0;
bbb=BearXML.xxx.length();
bb=bbb*180;
for (var j:uint=0; j< BearXML.xxx.length(); j++) {
var bpp:bp=new bp;
bpp.pic.source=BearXML.xxx.path[j];
bpp.t.text=BearXML.xxx.span[j];
bpp.x=180*j;
bpp.y=5;
bpp.name="bear"+j;
BearPic.addChild(bpp);
BearPic.x=10;
BearPic.y=5;
var bpx:bp=new bp;
bpx.pic.source=BearXML.xxx.path[j];
bpx.t.text=BearXML.xxx.span[j];
bpx.x=180*j;
bpx.y=5;
bpx.name="n"+j;
BearPic1.addChild(bpx);
BearPic1.x=659;
BearPic1.y=5;
}
if(bbb>3){
myTimer.start();
}else {
trace("图片未超过3张不滚动");
}
}
var i=0;
var t=0;
var z=0;
var isMov:Boolean=true;
var myTimer:Timer=new Timer(10,0);
myTimer.addEventListener(TimerEvent.TIMER,timeFun);
function timeFun(evt:TimerEvent):void {
if(isMov){
BearPic.x -= 1;
i++
}
//trace("一:"+i);
if(i > bb-640){
myTimer1.addEventListener(TimerEvent.TIMER,T2);
myTimer1.start();
}
if(i > bb){
BearPic.x=659;
myTimer.removeEventListener(TimerEvent.TIMER,timeFun);
i=0;
//trace("一:归档------------------------------------------");
}
}
var myTimer1:Timer=new Timer(10,0);
myTimer1.addEventListener(TimerEvent.TIMER,T2);
function T2(eve:Event):void{
var DV9:int=(bbb-3)*180+540;
if(isMov){
BearPic1.x -= 1;
t++
}
//trace("二:"+t);
if(t > bb*2-DV9){
myTimer2.addEventListener(TimerEvent.TIMER,T3);
myTimer2.start();
}
if(t > bb+659){
BearPic1.x=659;
myTimer1.removeEventListener(TimerEvent.TIMER,T2);
t=0;
//trace("二:归档------------------------------------------");
}
}
var myTimer2:Timer=new Timer(10,0);
myTimer2.addEventListener(TimerEvent.TIMER,T3);
function T3(eve:Event):void{
var ORG:int=(bbb-3)*180+530;
if(isMov){
BearPic.x -= 1;
z++
}
//trace("二:"+t);
if(z > bb*2-ORG){
myTimer1.addEventListener(TimerEvent.TIMER,T2);
myTimer1.start();
}
if(z > bb+659){
BearPic.x=659;
myTimer2.removeEventListener(TimerEvent.TIMER,T3);
z=0;
//trace("二:归档------------------------------------------");
}
}
function OVER(e:Event) {
isMov=false;
}
function OUT(e:Event) {
isMov=true;
}
BearPic.addEventListener(MouseEvent.MOUSE_OVER,OVER);
BearPic.addEventListener(MouseEvent.MOUSE_OUT,OUT);
BearPic1.addEventListener(MouseEvent.MOUSE_OVER,OVER);
BearPic1.addEventListener(MouseEvent.MOUSE_OUT,OUT);
代码就这些了 XML如下
<?xml version="1.0" encoding="utf-8"?>
<bearpic id="6">
<img id="1">
<path>7.jpg</path>
<titlee>这个是第一个</titlee>
</img>
<img id="2">
<path>2.jpg</path>
<titlee>这个是第二个</titlee>
</img>
<img id="3">
<path>3.jpg</path>
<titlee>这个是第三个</titlee>
</img>
<img id="4">
<path>4.jpg</path>
<titlee>这个是第四个</titlee>
</img>
<img id="5">
<path>5.jpg</path>
<titlee>这个是第五个</titlee>
</img>
<img id="6">
<path>6.jpg</path>
<titlee>这个是第六个</titlee>
</img>
</bearpic>
<bearpic id="6">
<img id="1">
<path>7.jpg</path>
<titlee>这个是第一个</titlee>
</img>
<img id="2">
<path>2.jpg</path>
<titlee>这个是第二个</titlee>
</img>
<img id="3">
<path>3.jpg</path>
<titlee>这个是第三个</titlee>
</img>
<img id="4">
<path>4.jpg</path>
<titlee>这个是第四个</titlee>
</img>
<img id="5">
<path>5.jpg</path>
<titlee>这个是第五个</titlee>
</img>
<img id="6">
<path>6.jpg</path>
<titlee>这个是第六个</titlee>
</img>
</bearpic>
开始竟然没放出源码 汗
下载文件
Jul
22
今天就把公司的一个项目中的一些心得拿出来策一策
需求:导航菜单点击后保持变色状态,为了SEO不允许使用FLASH。
方法:JS对Cookie的操作
过程:
bearcookie.js文件内容如下
页面代 如下
并在body中写入 onload="bearset();" 来执行读取Cookie
在菜单上写入 onclick="setcookies('nav1')" 来执行添 Cookie
说明
killErrors() 方法 这个是为了清除JS错误(就是浏览器左下角的黄色感叹号)用的
bearset() 方法 读取Cookie并设置导航菜单的class值 以及改变某些图片( 为在这里我用了2 图片来表达是当前状态还是过去状态)
setcookies() 方法 添 Cookie的方法
遇到的问题:
我们的这个项目是多文件夹结构,起初在写JS添 Cookie的时候并未注意 Cookie中 path的运用, 成了不同级别的目录读取的Cookie紊乱的问题。
时间问题也很重要,时间没设置对的话是不会产生Cookie文件的,这个问题也是我一时大意,少写了个";"号的缘故。
在网上找了很多资料,最后还是自己详细的去了解了一下Cookie设置的基础和结构才解决了问题,基础真的很重要。
需求:导航菜单点击后保持变色状态,为了SEO不允许使用FLASH。
方法:JS对Cookie的操作
过程:
bearcookie.js文件内容如下
//添 cookie function addCookie(name,value){ var destoryTime = new Date(); destoryTime.setTime(destoryTime.getTime() + 24 * 3600 * 1000); var expireTime = destoryTime.toGMTString(); document.cookie = name+"="+value+""+ ";expires=" + expireTime + "; path=/;"; }
//获取cookie function getCookie(name){ var strCookie=document.cookie; var arrCookie=strCookie.split("; "); for(var i=0;i<arrCookie.length;i++){ var arr=arrCookie[i].split("="); if(arr[0]==name)return arr[1]; } return ""; }
//获取cookie function getCookie(name){ var strCookie=document.cookie; var arrCookie=strCookie.split("; "); for(var i=0;i<arrCookie.length;i++){ var arr=arrCookie[i].split("="); if(arr[0]==name)return arr[1]; } return ""; }
页面代 如下
<script type="text/javascript"> function killErrors() { return true; } window.onerror = killErrors; function bearset(){ var zjb = getCookie("bearjia"); document.getElementById(zjb).className="li2"; document.getElementById(zjb+"a").src="/html/images/"+zjb+"b"+".jpg"; } function setcookies(value) { addCookie("bearjia",value); } </script>
并在body中写入 onload="bearset();" 来执行读取Cookie
在菜单上写入 onclick="setcookies('nav1')" 来执行添 Cookie
说明
killErrors() 方法 这个是为了清除JS错误(就是浏览器左下角的黄色感叹号)用的
bearset() 方法 读取Cookie并设置导航菜单的class值 以及改变某些图片( 为在这里我用了2 图片来表达是当前状态还是过去状态)
setcookies() 方法 添 Cookie的方法
遇到的问题:
我们的这个项目是多文件夹结构,起初在写JS添 Cookie的时候并未注意 Cookie中 path的运用, 成了不同级别的目录读取的Cookie紊乱的问题。
时间问题也很重要,时间没设置对的话是不会产生Cookie文件的,这个问题也是我一时大意,少写了个";"号的缘故。
在网上找了很多资料,最后还是自己详细的去了解了一下Cookie设置的基础和结构才解决了问题,基础真的很重要。
Jul
13
Flash在这个时代可以说是最佳的WEB富媒体解决方案
1,表现力极强(当然,那些说flash能做到的js也能做到的人除外,因为这个说法太无知了)
2,跨平台性(没有什么操作平台不支持的,微软的“淫 光”还是需要做出对.net的割舍才行,目前在谷歌浏览器的版本还在公测中,期待)
3,B/S结构下的C/S(好处也有坏处也有,目前天朝的网络环境太落后了,区域性差别过大,在上海随便找个KFC打开笔记本上网的速度都比,白帝城的8M电信都要快,3G就算了,那玩意掉线很令人恼火,而且我还是坐在家里。服务器更新客户端,即可完成更新。一次� 载,以后快速运行。而JS还需要重新对脚本解释。)
4,OOP(flash中的脚本升级到as3.0后带来了OOP,想到什么就能做到什么。起初我已经把大话2逐步搬到了flash。个人的BearBox还在完善中,这是一种游戏编辑器,目前还只有一个地图编辑器)
5,和各种编程语言的紧密结合(dotnet、java、php……几乎主流的都有相应的方法)
6,强大的流媒体服务管理器(FMS、RED5、SFS除FMS等 所不能外其它都还需要自己编写点东西)
用flash编写web网游的好处已经举了些,其实上述内容都是废话
我们将选用flash的框架flex来完成整个游戏的架子,虽然有很多的第三方控件可用,但是目前来说,我不觉得他们好在哪里。
本次就来介绍登录部分的结构
/*-----------------------------------登录界面----------------------------------*/
Login.mxml
/*-----------------------------------代码部分----------------------------------*/
enterState(进入状态)
exitState(退出状态)
EnterGame(进入游戏)
ExitGame(退出游戏)
GameObjectManager.as
/*-----------------------------------代码部分----------------------------------*/
1,表现力极强(当然,那些说flash能做到的js也能做到的人除外,因为这个说法太无知了)
2,跨平台性(没有什么操作平台不支持的,微软的“淫 光”还是需要做出对.net的割舍才行,目前在谷歌浏览器的版本还在公测中,期待)
3,B/S结构下的C/S(好处也有坏处也有,目前天朝的网络环境太落后了,区域性差别过大,在上海随便找个KFC打开笔记本上网的速度都比,白帝城的8M电信都要快,3G就算了,那玩意掉线很令人恼火,而且我还是坐在家里。服务器更新客户端,即可完成更新。一次� 载,以后快速运行。而JS还需要重新对脚本解释。)
4,OOP(flash中的脚本升级到as3.0后带来了OOP,想到什么就能做到什么。起初我已经把大话2逐步搬到了flash。个人的BearBox还在完善中,这是一种游戏编辑器,目前还只有一个地图编辑器)
5,和各种编程语言的紧密结合(dotnet、java、php……几乎主流的都有相应的方法)
6,强大的流媒体服务管理器(FMS、RED5、SFS除FMS等 所不能外其它都还需要自己编写点东西)
用flash编写web网游的好处已经举了些,其实上述内容都是废话
我们将选用flash的框架flex来完成整个游戏的架子,虽然有很多的第三方控件可用,但是目前来说,我不觉得他们好在哪里。
本次就来介绍登录部分的结构
/*-----------------------------------登录界面----------------------------------*/
Login.mxml
/*-----------------------------------代码部分----------------------------------*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="400" frameRate="100" creationComplete="creationComplete()" enterFrame="enterFrame(event)" currentState="MainMenu">
<mx:states>
<mx:State
name="Game"
enterState="enterGame(event)"
exitState="exitGame(event)">
</mx:State>
<mx:State name="MainMenu">
<mx:AddChild relativeTo="{myCanvas}" position="lastChild">
<mx:Button x="525" y="368" label="Start" id="btn Start" click="startGameClicked(event)"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Canvas x="0" y="0" width="100%" height="100%" id="myCanvas"/>
<mx:Script>
<![CDATA[
protected var inGame:Boolean = false;
public function creationComplete():void
{
}
public function enterFrame(event:Event):void
{
if(inGame)
{
GameObjectManager.Instance.enterFrame();
myCanvas.graphics.clear();
myCanvas.graphics.beginBitmapFill(GameObjectManager.Instance.backBuffer,null,false,false);
myCanvas.graphics.drawRect(0,0,this.width,this.height);
myCanvas.graphics.endFill();
}
}
protected function startGameClicked(event.Event):void
{
currentState="Game"
}
protected function enterGame(event:Event):void
{
GameObjectManager.Instance.startup();
inGame=true;
}
protected function exitGame(event:Event):void
{
inGame=false;
}
]]>
</mx:Script>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="400" frameRate="100" creationComplete="creationComplete()" enterFrame="enterFrame(event)" currentState="MainMenu">
<mx:states>
<mx:State
name="Game"
enterState="enterGame(event)"
exitState="exitGame(event)">
</mx:State>
<mx:State name="MainMenu">
<mx:AddChild relativeTo="{myCanvas}" position="lastChild">
<mx:Button x="525" y="368" label="Start" id="btn Start" click="startGameClicked(event)"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Canvas x="0" y="0" width="100%" height="100%" id="myCanvas"/>
<mx:Script>
<![CDATA[
protected var inGame:Boolean = false;
public function creationComplete():void
{
}
public function enterFrame(event:Event):void
{
if(inGame)
{
GameObjectManager.Instance.enterFrame();
myCanvas.graphics.clear();
myCanvas.graphics.beginBitmapFill(GameObjectManager.Instance.backBuffer,null,false,false);
myCanvas.graphics.drawRect(0,0,this.width,this.height);
myCanvas.graphics.endFill();
}
}
protected function startGameClicked(event.Event):void
{
currentState="Game"
}
protected function enterGame(event:Event):void
{
GameObjectManager.Instance.startup();
inGame=true;
}
protected function exitGame(event:Event):void
{
inGame=false;
}
]]>
</mx:Script>
</mx:Application>
enterState(进入状态)
exitState(退出状态)
EnterGame(进入游戏)
ExitGame(退出游戏)
GameObjectManager.as
/*-----------------------------------代码部分----------------------------------*/
Package
{
import mx.core.*;
import mx.collections.*;
import flash.display.*;
public class GameObjectManager
{
public var backBuffer:BitmapData;
public var clearColor:uint=0xFF0043AB;
protected statci var instance:GameObjectManager = null;
protected var lastFrame:Date;
static public function get Instance():GameObjectManager
{
if(instacne == null)
instance = new GameObjectManager();
return instance;
}
public function GameObjectManager()
{
if(instance != null)
throw new Error("Only one Singleton instance should be instantiated");
backBuffer = new BitmapData(Application.application.width,Application.application.height,false);
}
public function startup():void
{
lastFrame = new Data();
}
public function shutdown():void
{
}
public function enterFrame():void
{
var thisFrame:Date=new Date();
var seconds:Number=(thisFrame.getTime()-lastFrame.getTime())/1000.0;
lastFrame = thisFrame;
drawObjects();
}
protected function drawObjects():void
{
backBuffer.fillRect(backBuffer.rect,clearColor);
}
}
}
{
import mx.core.*;
import mx.collections.*;
import flash.display.*;
public class GameObjectManager
{
public var backBuffer:BitmapData;
public var clearColor:uint=0xFF0043AB;
protected statci var instance:GameObjectManager = null;
protected var lastFrame:Date;
static public function get Instance():GameObjectManager
{
if(instacne == null)
instance = new GameObjectManager();
return instance;
}
public function GameObjectManager()
{
if(instance != null)
throw new Error("Only one Singleton instance should be instantiated");
backBuffer = new BitmapData(Application.application.width,Application.application.height,false);
}
public function startup():void
{
lastFrame = new Data();
}
public function shutdown():void
{
}
public function enterFrame():void
{
var thisFrame:Date=new Date();
var seconds:Number=(thisFrame.getTime()-lastFrame.getTime())/1000.0;
lastFrame = thisFrame;
drawObjects();
}
protected function drawObjects():void
{
backBuffer.fillRect(backBuffer.rect,clearColor);
}
}
}






