读书人

flex设置舞台大小如何弄

发布时间: 2013-04-21 21:18:07 作者: rapoo

flex设置舞台大小怎么弄?
打算在网页里用swf显示摄像头,但是这个摄像头的video无法控制大小


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="showCamera(event)">
<fx:Script>
<![CDATA[
import flash.net.FileReference;
import flash.net.URLRequest;

import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.graphics.ImageSnapshot;
import mx.graphics.codec.PNGEncoder;
import mx.rpc.http.HTTPService;


private var camera:Camera;
privatevar video:Video;
protected function showCamera(event:FlexEvent):void{


camera=Camera.getCamera();
if(camera!=null){
video=new Video(200,150);
video.attachCamera(camera);
video.x=0;
video.y=0;
myUI.addChild(video);
}else{
Alert.show("对不起,您没有摄像头!");
}
}
public function takePic(event:MouseEvent):void{
Alert.show("clicked");
var jpgSource:BitmapData= new BitmapData(video.width,video.height);
var myMatrix:Matrix=new Matrix();
jpgSource.draw(video,myMatrix);
var png:PNGEncoder = new PNGEncoder();
var imgbyte:ByteArray=png.encode(jpgSource);

var request:URLRequest = new URLRequest("http://127.0.0.1:8080/takePic/servlet/getPic");
var loader:Loader = new Loader();
request.data = imgbyte;
request.method = flash.net.URLRequestMethod.POST;
request.contentType = "application/octet-stream";
loader.load( request );

}

]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<mx:UIComponent width="200" height="150" id="myUI" />
<s:Button x="100" y="150" label="拍照" id="imgBtn" click="takePic(event)"/>
</s:Application>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>${title}</title>
<meta name="google" value="notranslate" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
// For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
var swfVersionStr = "${version_major}.${version_minor}.${version_revision}";


// To use express install, set to playerProductInstall.swf, otherwise the empty string.
var xiSwfUrlStr = "${expressInstallSwf}";
var flashvars = {};
var params = {};
params.quality = "high";
params.bgcolor = "${bgcolor}";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = {};
attributes.id = "${application}";
attributes.name = "${application}";
attributes.align = "middle";
swfobject.embedSWF(
"${swf}.swf", "flashContent",
"200px", "180px",//<----------------------------这里有问题!!!!
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
// JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
swfobject.createCSS("#flashContent", "display:block;text-align:left;");



</script>
</head>

<body>
<div id="flashContent"></div>
</body>
</html>


1.以上有问题部分曾经为"${width}","${height}",但是这样做swf会铺满整个屏幕。
2.我把宽度改为400px,高度改为300px,这样就可以显示如下
flex设置舞台大小如何弄
flex设置舞台大小如何弄
3.但是如果把宽度改为200,高度改为180的话,就只能如下
flex设置舞台大小如何弄

怎么改了大小那个flash安全设置的东西就出不来了??
[解决办法]
flex学的不多:[SWF(width="1000",height="750",backgroundColor="#D6E3F7",frameRate="100")] 我们知道使用Flash CS3 /Flash CS4 创建Flash 项目可以很方便的在项目属性面板上设置项目的舞台的大小,但当我们用Flex / Flash Builder 来做Flash 时候就没有直观的属性来设置舞台大小了。

读书人网 >其他服务器

热点推荐