My AS3 game won't go to full screen - actionscript-3

I'm making an AS3 platform game. I don't know why but it won't go to full screen...
Here's my code :
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.getTimer;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
public class PlatformGame extends MovieClip {
// movement constants
static const gravity:Number = .004;
// screen constants
static const edgeDistance:Number = 100;
// object arrays
private var fixedObjects:Array;
private var otherObjects:Array;
// hero and enemies
private var hero:Object;
private var enemies:Array;
// game state
private var playerObjects:Array;
private var gameScore:int;
private var gameMode:String = "start";
private var playerLives:int;
private var lastTime:Number = 0;
// start game
public function startPlatformGame() {
addEventListener(Event.ADDED_TO_STAGE, startGame);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
playerObjects = new Array();
gameScore = 0;
gameMode = "play";
playerLives = 3;
}
Do you know what could be the problem ? (I've just put the begining if my code, if you think it's necessary that I put all my code, don't hesitate to tell me)

Read this Adobe documentation:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS2E9C7F3B-6A7C-4c5d-8ADD-5B23446FBEEB.html

Related

ActionScript 3: Zoom functions - drag does not show

I've included a zoom functionality similar to the one explained at this website: http://www.flashandmath.com/howtos/zoom/
Even though it does indeed work in terms of the possibility of moving the image on my stage, the drag-animation is not present, meaning there will be no "movement" of my image, just a sudden change in position.
The problem followed my attempt to change the concept from timeline-based to class-based.
Here is my Main class:
package
{
import flash.display.MovieClip;
import flash.utils.Dictionary;
import flash.display.Shape;
import fl.transitions.Fly;
import fl.motion.MatrixTransformer;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.ui.Mouse;
public class Main extends Sprite
{
public static var scale:Number = 1;
private var _rootMC:MovieClip;
// ------------------------------
public var bg_image:Sprite;
public var spImage:Sprite;
public var mat:Matrix;
public var mcIn:MovieClip;
public var mcOut:MovieClip;
public var boardWidth:int = 980;
public var boardHeight:int = 661;
public var boardMask:Shape;
public var externalCenter:Point;
public var internalCenter:Point;
public static var scaleFactor:Number = 0.8;
public static var minScale:Number = 0.25;
public static var maxScale:Number = 10.0;
//-------------------------------
public function Main(rootMC:MovieClip)
{
_rootMC = rootMC;
bg_image = new image();
this.graphics.beginFill(0xB6DCF4);
this.graphics.drawRect(0,0,boardWidth,boardHeight);
this.graphics.endFill();
spImage = new Sprite();
this.addChild(spImage);
boardMask = new Shape();
boardMask.graphics.beginFill(0xDDDDDD);
boardMask.graphics.drawRect(0,0,boardWidth,boardHeight);
boardMask.graphics.endFill();
boardMask.x = 0;
boardMask.y = 0;
this.addChild(boardMask);
spImage.mask = boardMask;
minScale = boardWidth / bg_image.width;
mcIn = new InCursorClip();
mcOut = new OutCursorClip();
bg_image.addChild(mcIn);
bg_image.addChild(mcOut);
bg_image.scaleX = minScale;
bg_image.scaleY = minScale;
spImage.addChild(bg_image);
spImage.addChild(mcIn);
spImage.addChild(mcOut);
spImage.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
_rootMC.stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
spImage.addEventListener(MouseEvent.CLICK, zoom);
_rootMC.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
_rootMC.stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
}
private function startDragging(mev:MouseEvent):void
{
spImage.startDrag();
}
private function stopDragging(mev:MouseEvent):void
{
spImage.stopDrag();
}
private function zoom(mev:MouseEvent):void
{
if ((!mev.shiftKey)&&(!mev.ctrlKey))
{
return;
}
if ((mev.shiftKey)&&(mev.ctrlKey))
{
return;
}
externalCenter = new Point(spImage.mouseX,spImage.mouseY);
internalCenter = new Point(bg_image.mouseX,bg_image.mouseY);
if (mev.shiftKey)
{
bg_image.scaleX = Math.max(scaleFactor*bg_image.scaleX, minScale);
bg_image.scaleY = Math.max(scaleFactor*bg_image.scaleY, minScale);
}
if (mev.ctrlKey)
{
bg_image.scaleX = Math.min(1/scaleFactor*bg_image.scaleX, maxScale);
bg_image.scaleY = Math.min(1/scaleFactor*bg_image.scaleY, maxScale);
}
mat = this.transform.matrix.clone();
MatrixTransformer.matchInternalPointWithExternal(mat,internalCenter,externalCenter);
bg_image.transform.matrix = mat;
}
private function keyHandler(ke:KeyboardEvent):void
{
mcIn.x = spImage.mouseX;
mcIn.y = spImage.mouseY;
mcOut.x = spImage.mouseX;
mcOut.y = spImage.mouseY;
mcIn.visible = ke.ctrlKey;
mcOut.visible = ke.shiftKey;
if (ke.ctrlKey || ke.shiftKey)
{
Mouse.hide();
}
else
{
Mouse.show();
}
}
}
}
Here is my image class:
package {
import fl.motion.MatrixTransformer;
import flash.display.MovieClip;
import flash.utils.Dictionary;
import flash.display.Shape;
import fl.transitions.Fly;
import fl.motion.MatrixTransformer;
import flash.events.MouseEvent;
public class image extends MovieClip
{
public function image()
{
this.width = 980
this.height = 500
this.y = 0
this.x = 0
}
}
I know this is a lot of code, but I am really stuck :(
On your MOUSE_DOWN handler, you need to start listening to the MOUSE_MOVE event.
On your MOUSE_UP handler, you need to stop listening to the MOUSE_MOVE event.
Not sure if you are already doing this.
In your MOUSE_MOVE event handler, you need to update the x / y positions of the image, in a similar way to what you are probably doing on the MOUSE_UP handler.

TypeError 1009 AS3

I have looked through this code over and over and over but just cant seem to find where the problem is rooted. Here is the error message:
"TypeError: Error #1009:
at com.senocular.utils::KeyObject/construct()[C:\Users\nti\Desktop\Ship game\com\senocular\utils\KeyObject.as:29]
at com.senocular.utils::KeyObject()[C:\Users\nti\Desktop\Ship game\com\senocular\utils\KetyObject.as:23]
at com.asgamer.basics1::Ship()[C:\Users\nti\Desktop\Ship game\com\asgamer\basics1\Ship.as:24]
at com.asgamer.basics1::Engine()[C:\Users\nti\Desktop\Ship game\com\asgamer\basics1\Engine.as:17]
"
It's certainly not in the KeyObject class since that's downloaded and not changed in any(and has worked before), but here's that snippet of code anyway(notice the markers where the lines are):
dynamic public class KeyObject extends Proxy {
private static var stage:Stage;
private static var keysDown:Object;
public function KeyObject(stage:Stage) {
construct(stage); <---------------------------------------------LINE 23
}
public function construct(stage:Stage):void {
KeyObject.stage = stage;
keysDown = new Object();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed); <--- LINE 29
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
}
Here are the parts of code that's causing the error:
package com.asgamer.basics1
{
import flash.display.MovieClip;
import flash.display.Stage;
import com.senocular.utils.KeyObject;
import flash.ui.Keyboard;
import flash.events.Event;
public class Ship extends MovieClip
{
private var stageRef:Stage;
private var key:KeyObject;
private var speed:Number = 0.5;
private var vx:Number = 0;
private var vy:Number = 0;
private var friction:Number = 0.93;
private var maxspeed:Number = 8;
public function Ship(stageRef:Stage)
{
this.stageRef = stageRef;
key = new KeyObject(stageRef); <----------------------------- LINE 24
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
and here's the engine class:
package com.asgamer.basics1
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class Engine extends MovieClip
{
private var numStars:int = 80;
private var enemyList:Array = new Array();
private var ourShip:Ship;
public function Engine() : void
{
ourShip = new Ship(stage); <------------------------------- LINE 17
ourShip.x = stage.stageWidth / 2;
ourShip.y = stage.stageHeight / 2;
stage.addChild(ourShip);
for (var i:int = 0; i < numStars; i++)
{
stage.addChildAt(new Star(stage), stage.getChildIndex(ourShip));
}
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
I would really, really appreciate if someone would answer since this project is crucial to my final grades!
Instance of the Engine class is being constructed at the moment, when the stage property is still null. This means that the Engine class instance hasn't been added to the display list yet.
See: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#stage

Stage resizing in AS3 Flash

Heyyyy, i'm trying to find a simple way ( or as simple as possible, i'm a newbie in AS3) to resize stage while doing a mouse over event. For details, the original size is 670x40 and the target size is 670x230. Also, please answer for movieclip.
You can't dynamically change the stage size from code, but You can change it with the JS.
See here.
Sorry, this is an old post, but I hope this could help someone, I saw a lot of problems and confusions between stage.width, stage.height and stage.stageWidth, stage.stageHeight...
All you've to know is that you must use stage.align = StageAlign.TOP_LEFT or StageAlign.TOP and stage.scaleMode = StageScaleMode.NO_SCALE;
All should be works fine then...
This is a way to re size some content when an Event.Resize is triggered...
Create a Main.as class file in a "com" package (copy paste the simple code here bellow to figure you out how it may works) and set the main class in flash to "com.Main".
Why do you want to do it when a MouseEvent is triggered?
Seems like nonsense...
The Event.RESIZE is more efficient AMHO in this case.
The Event.ADDED will initialize the items you want to resize...
package com
{
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.text.TextField;
public class Main extends MovieClip
{
public static const ORANGE:int = 0xff9900;
private var bg:MovieClip;
private var bg_mask:MovieClip;
private var marginx:int = 10;
private var marginy:int = 10;
private var display:MovieClip;
private var displayTextField:TextField;
private var ellipseWidth:int = 90;
private var ellipseHeight:int = 90;
public function Main()
{
super();
bg = new MovieClip();
bg_mask = new MovieClip();
display = new MovieClip();
displayTextField = new TextField();
this.addChild(bg);
this.addChild(bg_mask);
this.addChild(display);
this.display.addChild(displayTextField);
displayTextField.text = "";
displayTextField.x = ellipseWidth/Math.PI;
displayTextField.y = ellipseHeight/Math.PI;
stage.align = StageAlign.TOP_LEFT; // or StageAlign.TOP
stage.scaleMode = StageScaleMode.NO_SCALE;
drawBackground();
display.mask = bg_mask;
addListeners();
}
private function drawBackground(thickness:int=1,lineColor:int=0x000000,lineAlpha:Number=0.5,fillColor:int=ORANGE,fillAlpha:Number=0.5):void{
var g:Graphics = bg.graphics;
g.clear();
g.lineStyle(thickness,lineColor,lineAlpha);
g.beginFill(fillColor,fillAlpha);
g.drawRoundRect(marginx,marginy,this.stage.stageWidth-marginx*2,this.stage.stageHeight-marginy*2,ellipseWidth,ellipseHeight);
g.endFill();
}
private function drawMask():void{
var g:Graphics = bg_mask.graphics;
g.clear();
g.lineStyle(1,0x000000,0.3);
g.beginFill(0xcccccc,0.1);
g.drawRoundRect(marginx,marginy,this.stage.stageWidth-marginx*2,this.stage.stageHeight-marginy*2,90,90);
g.endFill();
}
private function addListeners():void{
stage.addEventListener(Event.ADDED,updateLabel);
stage.addEventListener(Event.RESIZE,updateLabel);
}
private function updateLabel(e:Event):void{
updateDisplay();
drawBackground();
drawMask();
}
private function updateDisplay():void{
var tf:TextField = displayTextField;
tf.text = ("{" + this.stage.stageWidth + ";" + this.stage.stageHeight + "}");
}
}
}

away3d and cs6 external as3 file

i need some help to lunch external action script file lets say i have this file :
Basic_SkyBox.as
and this the code for it :
package
{
import away3d.cameras.lenses.*;
import away3d.containers.*;
import away3d.entities.*;
import away3d.materials.*;
import away3d.materials.methods.*;
import away3d.primitives.*;
import away3d.textures.*;
import away3d.utils.*;
import flash.display.*;
import flash.events.*;
import flash.geom.Vector3D;
[SWF(backgroundColor="#000000", frameRate="60", quality="LOW")]
public class Basic_SkyBox extends Sprite
{
// Environment map.
[Embed(source="../embeds/skybox/snow_positive_x.jpg")]
private var EnvPosX:Class;
[Embed(source="../embeds/skybox/snow_positive_y.jpg")]
private var EnvPosY:Class;
[Embed(source="../embeds/skybox/snow_positive_z.jpg")]
private var EnvPosZ:Class;
[Embed(source="../embeds/skybox/snow_negative_x.jpg")]
private var EnvNegX:Class;
[Embed(source="../embeds/skybox/snow_negative_y.jpg")]
private var EnvNegY:Class;
[Embed(source="../embeds/skybox/snow_negative_z.jpg")]
private var EnvNegZ:Class;
//engine variables
private var _view:View3D;
//scene objects
private var _skyBox:SkyBox;
private var _torus:Mesh;
/**
* Constructor
*/
public function Basic_SkyBox()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//setup the view
_view = new View3D();
addChild(_view);
//setup the camera
_view.camera.z = -600;
_view.camera.y = 0;
_view.camera.lookAt(new Vector3D());
_view.camera.lens = new PerspectiveLens(90);
//setup the cube texture
var cubeTexture:BitmapCubeTexture = new BitmapCubeTexture(Cast.bitmapData(EnvPosX), Cast.bitmapData(EnvNegX), Cast.bitmapData(EnvPosY), Cast.bitmapData(EnvNegY), Cast.bitmapData(EnvPosZ), Cast.bitmapData(EnvNegZ));
//setup the environment map material
var material:ColorMaterial = new ColorMaterial(0xFFFFFF, 1);
material.specular = 0.5;
material.ambient = 0.25;
material.ambientColor = 0x111199;
material.ambient = 1;
material.addMethod(new EnvMapMethod(cubeTexture, 1));
//setup the scene
_torus = new Mesh(new TorusGeometry(150, 60, 40, 20), material);
_view.scene.addChild(_torus);
_skyBox = new SkyBox(cubeTexture);
_view.scene.addChild(_skyBox);
//setup the render loop
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
stage.addEventListener(Event.RESIZE, onResize);
onResize();
}
/**
* render loop
*/
private function _onEnterFrame(e:Event):void
{
_torus.rotationX += 2;
_torus.rotationY += 1;
_view.camera.position = new Vector3D();
_view.camera.rotationY += 0.5*(stage.mouseX-stage.stageWidth/2)/800;
_view.camera.moveBackward(600);
_view.render();
}
/**
* stage listener for resize events
*/
private function onResize(event:Event = null):void
{
_view.width = stage.stageWidth;
_view.height = stage.stageHeight;
}
}
}
ok then i create new action script page how i can refer the above file script to run in main page of projects in flash cs6 ??
You need to set the Document Class to Basic_Skybox. Make sure the .fla and Basic_Skybox.as are in the same directory.
Here's a tutorial on doing so: http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/

adding noise to a video in actionscript

Before I begin, I would like to apologize if what I'm going to ask is to be considered as super newbie question.
so I was trying out Lee Brimelow's tutorial on creating a simple AR scene using actionscript3. (http://blog.theflashblog.com/?p=901)
It worked out pretty well, considering I have never created something out of Adobe Flex Builder before. (I installed Flex Builder right after I saw those tutorial)
here is the source code
package {
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Camera;
import flash.media.Video;
import flash.utils.ByteArray;
import org.libspark.flartoolkit.core.FLARCode;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
import org.libspark.flartoolkit.support.pv3d.FLARBaseNode;
import org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
[SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")]
public class FLARdemo extends Sprite
{
[Embed(source="pat1.pat", mimeType="application/octet-stream")]
private var pattern:Class;
[Embed(source="camera_para.dat", mimeType="application/octet-stream")]
private var params:Class;
private var fparams:FLARParam;
private var mpattern:FLARCode;
private var vid:Video;
private var cam:Camera;
private var bmd:BitmapData;
private var raster:FLARRgbRaster_BitmapData;
private var detector:FLARSingleMarkerDetector;
private var scene:Scene3D;
private var camera:FLARCamera3D;
private var container:FLARBaseNode;
private var vp:Viewport3D;
private var bre:BasicRenderEngine;
private var trans:FLARTransMatResult;
public function FLARdemo()
{
setupFLAR();
setupCamera();
setupBitmap();
setupPV3D();
addEventListener(Event.ENTER_FRAME, loop);
}
private function setupFLAR():void
{
fparams = new FLARParam();
fparams.loadARParam(new params() as ByteArray);
mpattern = new FLARCode(16, 16);
mpattern.loadARPatt(new pattern());
}
private function setupCamera():void
{
vid = new Video(640, 480);
cam = Camera.getCamera();
cam.setMode(640, 480, 30);
vid.attachCamera(cam);
addChild(vid);
}
private function setupBitmap():void
{
bmd = new BitmapData(640, 480);
bmd.draw(vid);
raster = new FLARRgbRaster_BitmapData(bmd);
detector = new FLARSingleMarkerDetector(fparams, mpattern, 80);
}
private function setupPV3D():void
{
scene = new Scene3D();
camera = new FLARCamera3D(fparams);
container = new FLARBaseNode();
scene.addChild(container);
var pl:PointLight3D = new PointLight3D();
pl.x = 1000;
pl.y = 1000;
pl.z = -1000;
var ml:MaterialsList = new MaterialsList({all: new FlatShadeMaterial(pl)});
var Cube1:Cube = new Cube(ml, 30, 30, 30);
var Cube2:Cube = new Cube(ml, 30, 30, 30);
Cube2.z = 50
var Cube3:Cube = new Cube(ml, 30, 30, 30);
Cube3.z = 100
container.addChild(Cube1);
container.addChild(Cube2);
container.addChild(Cube3);
bre = new BasicRenderEngine();
trans = new FLARTransMatResult();
vp = new Viewport3D;
addChild(vp);
}
private function loop(e:Event):void
{
bmd.draw(vid);
try
{
if(detector.detectMarkerLite(raster, 80) && detector.getConfidence() > 0.5)
{
detector.getTransformMatrix(trans);
container.setTransformMatrix(trans);
bre.renderScene(scene, camera, vp);
}
}
catch(e:Error){}
}
}
}
what I am asking is :
is it possible for us to add some noise in the final video output? I'm trying to find out the PSNR by adding noises respectively.
can I do some convolution between the noise and the video?
oh btw I'm doing this for my assignment in college. My prof wanted me to explain how exactly the FlarToolKit works. (details such as Matrix Projections, Obtaining Errors by doing Iterative Method, etc.)
Thank you.
Prama
Creating fine-grained noise dynamically is computationally expensive, so I generate low-res noise and scale it up. In your project, simply add the bitmap setup code after the addEventListener call and then add the single line to generate the noise to your activity loop.
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.media.Camera;
import flash.media.Video;
import flash.utils.getTimer;
public class NoiseMain extends Sprite
{
protected static const VID_WIDTH : uint = 640;
protected static const VID_HEIGHT : uint = 480;
protected static const NOISE_SCALE_X : Number = 4;
protected static const NOISE_SCALE_Y : Number = 2;
protected var _vid : Video;
protected var _noise : BitmapData;
protected var _composite : BitmapData;
protected var _matrix : Matrix;
public function NoiseMain()
{
// We're creating a webcam outlet, but not adding it to the stage since we want to post-process the image.
_vid = new Video(VID_WIDTH, VID_HEIGHT);
var cam : Camera = Camera.getCamera();
cam.setMode(VID_WIDTH, VID_HEIGHT, 30);
_vid.attachCamera(cam);
var w : uint = Math.ceil(VID_WIDTH / NOISE_SCALE_X);
var h : uint = Math.ceil(VID_HEIGHT / NOISE_SCALE_Y);
_noise = new BitmapData(w, h, false, 0xFFFFFF);
_composite = new BitmapData(VID_WIDTH, VID_HEIGHT, false, 0x000000);
var bmp : Bitmap = new Bitmap(_composite);
addChild(bmp);
_matrix = new Matrix(NOISE_SCALE_X, 0, 0, NOISE_SCALE_Y);
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
protected function enterFrameHandler(evt : Event) : void
{
_noise.noise(getTimer(), 204, 255, 7, true);
_composite.lock();
_composite.draw(_vid);
_composite.draw(_noise, _matrix, null, BlendMode.MULTIPLY);
_composite.unlock();
}
}
}
EDIT: I've revised my example to be more in line with what you're trying to do. You can tweak the noise scale constants to change the "texture" of the noise as well as messing with the strength of the noise (the 2nd and 3rd arguments to the noise() method) and the visual appearance of the noise by changing the BlendMode in the 2nd draw() call).