Totally non-responsive to keyboard presses - actionscript-3

This doesn't respond to pressing Enter -traces give no results.
Is there any way to do this that works?
This is just extra ridiculous writing to get past the ludicrous posting restrictions.
Yaddah.
boards.as
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.*;
import flash.ui.Keyboard;
import mx.core.BitmapAsset;
//import board;
import flash.accessibility.AccessibilityImplementation;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.text.AntiAliasType;
import flash.utils.describeType;
import flash.net.*;
import Set;
import StatusBox;
import Statusx;
import flash.display.InteractiveObject;
import flash.text.TextFieldType;
import flash.events.FocusEvent;
import fl.managers.FocusManager;
import flash.display.*;
import flash.display.Stage;
import flash.events.KeyboardEvent;
public class boxsprite extends Sprite
{
[Embed(source = "C:/Windows/Fonts/Verdana.ttf", fontName = "Verdana", fontWeight = "bold", advancedAntiAliasing = "true", mimeType = "application/x-font")]
public static const VERD:Class;
[Embed(source="../lib/box.gif")]
private var boxspriteClass:Class
[Embed(source = "../lib/m2.gif")]
private var m2:Class
[Embed(source = "../lib/m3.gif")]
private var m3:Class
[Embed(source="../lib/m4.gif")]
private var m4:Class
[Embed(source = "../lib/m5.gif")]
private var m5:Class
[Embed(source = "../lib/m6.gif")]
private var m6:Class
[Embed(source = "../lib/m7.gif")]
private var m7: Class
[Embed(source="../lib/m8.gif")]
private var m8: Class
[Embed(source = "../lib/m9.gif")]
private var m9: Class
private var m22:Bitmap;
private var m33:Bitmap;
private var m44:Bitmap;
private var m55:Bitmap;
private var m66:Bitmap;
private var m77:Bitmap;
private var m88:Bitmap;
private var m99:Bitmap;
private var boxsprite2:Bitmap;
internal var mode:uint=2;
internal var displaytext:String;
internal var setBox:Boolean = false;
internal var onBoard:Array = [0];
internal var playerRound:uint = 1;
internal var round:uint = 1;
internal var playernumber:uint;
internal var myTextBox:TextField = new TextField();
public function boxsprite():void
{
trace (mode);
boxsprite2=new boxspriteClass() as Bitmap;
this.addChild(boxsprite2);
m22 = new m2 as Bitmap;
this.addChild(m22);
m77= new m7 as Bitmap;
this.addChild(m77);
m66= new m6 as Bitmap;
this.addChild(m66);
m55= new m5 as Bitmap;
this.addChild(m55);
m44= new m4 as Bitmap;
this.addChild(m44);
m33= new m3 as Bitmap;
this.addChild(m33);
this.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown2);
}
private function myKeyDown2(e2:KeyboardEvent):void
{
if (e2.keyCode == Keyboard.ENTER)
{
trace("Enter pressed");
modeswitch();
}
else if (e2.keyCode ==Keyboard.H)
{
navigateToURL(new URLRequest("http://wp.me/P3FUQl-n"));
}
//else if (e.Keycode == Keyboard.Q)
function modeswitch():void
{ trace(mode);
switch(mode)
{
case 8:
{mode = 9;
choosetext(); }
case 9:
{mode = 2;
choosetext();
}
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
{mode = 3;
choosetext();}
startBox.addEventListener(KeyboardEvent.KEY_DOWN, kill);
This code part in
Board.as- appears to work.
function kill (e2:KeyboardEvent):void
{if (e2.keyCode == Keyboard.NUMBER_1)
{removeChild(this.startBox);
startBox = null;
}
else if (e2.keyCode == Keyboard.NUMBER_2)
{removeChild(this.startBox);
startBox = null;
}
else if (e2.keyCode == Keyboard.NUMBER_3)
{removeChild(this.startBox);
startBox = null;
}
else if (e2.keyCode == Keyboard.NUMBER_4)
{removeChild(this.startBox);
startBox = null;
}
else if (e2.keyCode == Keyboard.NUMBER_5)
{removeChild(startBox);
startBox = null; }
else if (e2.keyCode == Keyboard.NUMBER_6)
{ removeChild(this.board.startBox);
startBox = null;}
else if (e2.keyCode == Keyboard.ENTER)
{removeChild(startBox);
startBox = null;}
Maybe I've give up on keyboard for this part and use mouse events instead- in a previous structure I couldn't have done that as mouse was already occupied doing something but that should be freed up now.
By the way this isn't need on stage initialisation.

Your sprite will never receive any KeyboardEvent. You should add your event listeners directly to the stage. Of course, you have to obtain a link to the stage.
In your constructor delete
this.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown2);
And add the following:
//Your constructor
...
if(stage)
initKeyboardEvents();
else
addEventListener(Event.ADDED_TO_STAGE, initKeyboardEvents)
//End of constructor
...
//New function
private function initKeyboardEvents(e:Event = null):void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown2);
}

Related

How to stablish a Flash Peer-To-Peer Communication Over LAN (Without Cirrus/Stratus) with AIR

I'm trying to stream audio/video (I'm really only interested in Audio) in a LAN.
I've followed tutorials in internet which I've found very informative like the ones from Tom Krcha and thought would solve my problem. But until now I've not been successful in receiving the stream.
This is the code I'm using, can someone please point me out what am I missing?
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
import flash.net.GroupSpecifier;
import flash.net.NetConnection;
import flash.net.NetGroup;
import flash.net.NetStream;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
[SWF(width="640", height="920", frameRate="60")]
public class LoudApp extends Sprite {
private var _interpreterStartButton:TextField = new TextField();
private var _listenerStartButton:TextField = new TextField();
private var _connectedLabel:TextField = new TextField();
private var _userTextField:TextField = new TextField();
private var _stream:NetStream;
private var _netConnection:NetConnection;
private var _netGroup:NetGroup;
private var _isConnected:Boolean;
private var _listenerStream:NetStream;
private var _isListener:Boolean;
private var _video:Video;
public function LoudApp() {
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
private function connect():void{
_netConnection = new NetConnection();
_netConnection.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
_netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
_netConnection.connect("rtmfp:");
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function init(event:Event):void {
_listenerStartButton.border = _interpreterStartButton.border = true;
_listenerStartButton.backgroundColor = _interpreterStartButton.borderColor = 0;
_listenerStartButton.autoSize = _interpreterStartButton.autoSize = TextFieldAutoSize.LEFT;
_listenerStartButton.selectable = _interpreterStartButton.selectable = false;
_connectedLabel = new TextField();
_connectedLabel.y = 70;
_connectedLabel.text = "not connected";
_listenerStartButton.addEventListener(MouseEvent.CLICK, onButtonClicked, false, 0, true);
_interpreterStartButton.addEventListener(MouseEvent.CLICK, onButtonClicked, false, 0, true);
_interpreterStartButton.text = " Start\rTalking! ";
_listenerStartButton.text = " Start\rListening! ";
addChild(_interpreterStartButton);
addChild(_listenerStartButton);
addChild(_connectedLabel);
_listenerStartButton.x = 120;
var textFormat:TextFormat = new TextFormat(null, 30, 0x000000, true);
_listenerStartButton.setTextFormat(textFormat);
_interpreterStartButton.setTextFormat(textFormat);
// Init the Video
_video = new Video(stage.stageWidth, stage.stageHeight - 100);
_video.y = 100;
addChild(_video);
connect();
}
private function onButtonClicked(event:MouseEvent):void {
_isListener = event.target == _listenerStartButton;
_listenerStartButton.removeEventListener(MouseEvent.CLICK, onButtonClicked);
_interpreterStartButton.removeEventListener(MouseEvent.CLICK, onButtonClicked);
removeChild(_listenerStartButton) && removeChild(_interpreterStartButton);
/*_isConnected && */setupStream();
}
private function setupStream():void{
var groupSpecifier:GroupSpecifier = new GroupSpecifier("en-GB");
groupSpecifier.serverChannelEnabled = true;
groupSpecifier.multicastEnabled = true;
groupSpecifier.ipMulticastMemberUpdatesEnabled = true;
groupSpecifier.addIPMulticastAddress("225.225.0.1:30303");
// _netGroup = new NetGroup(_netConnection, groupSpecifier.groupspecWithAuthorizations());
// _netGroup.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
_stream = new NetStream(_netConnection, groupSpecifier.groupspecWithAuthorizations());
_stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
if(_isListener){
_video.attachNetStream(_stream);
_stream.receiveAudio(true);
// _stream.receiveVideo(false);
_stream.play('sound');
return;
}else{
if(!Microphone.isSupported) return;
_stream.attachAudio(Microphone.getMicrophone());
// var camera:Camera = Camera.getCamera();
// _stream.attachCamera(camera);
_stream.publish("sound", "live");
// _video.attachCamera(camera);
}
}
private function netStatus(event:NetStatusEvent):void{
switch(event.info.code){
case "NetConnection.Connect.Success":
// _isConnected = true;
// _connectedLabel.text = "CONNECTED !";
break;
case "NetGroup.Connect.Success":
_isConnected = true;
_connectedLabel.text = "CONNECTED !";
break;
case "NetStream.Connect.Success":
break;
case "NetStream.Publish.Start":
break;
}
}
private function set listenerStream(value:NetStream):void {
_listenerStream = value;
}
}
}
Thank you in forward.
I was pointed out by Tom Krcha that some networks block multicast. And it was in deed the case.
I got a fresh router to test the apps again and it all worked perfectly.

Error 1046:Type not found or was not a compile-time constant:Listing2

I am trying to add a movieclip that is generated through a loop from SearchVectorTest class file, and put that into sresultnologin class file. Then i will make that movieclip clickable, and when clicked, goes to next class,display a new stage, pull the information from that specific stored in that movieclip, and pull the rest of the information from the database and display them.
I am having an error at the moment, Type not found. I can't seem to add the Movieclip(box) as a button. on this line var newListing:Listing2 = Bolder.getChildAt(0);
sresultnologin.as
package com.clark
{
import com.clark.SearchVectorTest;
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
import fl.controls.Button;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class sresultnologin extends MovieClip {
public var s1:Searchreult = new Searchreult ();
public function sresultnologin(){
// init
addEventListener(Event.ADDED_TO_STAGE, onadded);
function onadded (event:Event):void{
s1.x=-10;
s1.y=10;
addChild(s1);
}
var s3:SearchVectorTest= new SearchVectorTest(new Vector.<searchVO1>);
addChild (s3);
s1.SRhome.addEventListener(MouseEvent.CLICK, fl_ClickToGoTol);
s1.ARsearch.addEventListener(MouseEvent.CLICK, fl_ClickToGosearch);
if( s3.listings.length > 0 )
{
// get the first listing in the listing array
var newListing:Listing8 = s3.listings[0];
newListing.addEventListener(MouseEvent.CLICK, gotoscener);
}
else
{
}
}
// private methods
private function gotoscener(event:MouseEvent):void
{
var s9:Listingdetail = new Listingdetail ();
removeChild(s1);
addChild(s9);
}
private function fl_ClickToGoTol(event:MouseEvent):void
{
var s9:Account = new Account ();
removeChild(s1);
addChild(s9);
}
private function fl_ClickToGosearch(event:MouseEvent):void
{
var s9:searchVO1 = new searchVO1 ();
removeChild(s1);
addChild(s9);
}
}
}
SearchVectorTest.as
package com.clark
{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class SearchVectorTest extends MovieClip
{
public var listings:Vector.<Listing8>;
public function SearchVectorTest(test:Vector.<searchVO1>)
{
for (var j:int = 0; j < test.length; j++)
{
trace(test[j].nobed);
trace(test[j].zip);
trace(test[j].Location);
trace(test[j].price);
}
var len:int = test ? test.length : 0;
// create your vector for your listings with the len size
listings = new Vector.<Listing8>(len, true);
var currentY:int = 200;
for (var k:int = 0; k < test.length; k++)
{
var Bolder:Listing8 = new Listing8();
Bolder.x=20;
var bf:TextField = new TextField();
var bf1:TextField = new TextField();
var bf2:TextField = new TextField();
var bf3:TextField = new TextField();
bf3.width = 100;
bf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);
bf.width = 100;
bf.autoSize = TextFieldAutoSize.CENTER;
bf1.width = 100;
bf1.autoSize = TextFieldAutoSize.CENTER;
bf2.autoSize = TextFieldAutoSize.CENTER;
bf3.autoSize = TextFieldAutoSize.CENTER;
bf3.width = 100;
bf1.y= bf.height+5;
bf.text = test[k].nobed;
bf1.text = test[k].zip;
bf2.text = test[k].Location;
bf3.text = test[k].price;
bf.x = (Bolder.height-bf.height)*.2
Bolder.addChild(bf);
Bolder.addChild(bf1);
Bolder.addChild(bf2);
Bolder.addChild(bf3);
Bolder.properties = test[k].nobed;
Bolder.properties = test[k].zip;
// position the object based on the accumulating variable.
Bolder.y = currentY;
addChild(Bolder);
Bolder.mouseChildren = false; // ignore children mouseEvents
Bolder.mouseEnabled = true; // enable mouse on the object - normally set to true by default
Bolder.useHandCursor = true; // add hand cursor on mouse over
Bolder.buttonMode = true;
listings[k] = Bolder;
currentY += Bolder.height + 10;
}
}
}
}
SearchVO1
package com.clark
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
import fl.controls.Button;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLLoaderDataFormat;
import flash.net.URLVariables;
import flash.utils.*;
import flash.sampler.NewObjectSample;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
public class searchVO1 extends MovieClip {
private var Arvariables:URLVariables;
private var SrSend:URLRequest;
private var SaLoader:URLLoader;
public var nobed:String;
public var zip:String;
public var Location:String;
public var price:String;
public var callMethod:Function;
public var s1:searchpage = new searchpage ();
public function searchVO1():void{
addEventListener(Event.ADDED_TO_STAGE, onadded); // init
function onadded (event:Event):void{
s1.x=-10;
s1.y=10;
addChild(s1);
s1.account.addEventListener(MouseEvent.CLICK, fl_ClickToGoToaccount);
s1.searchs.addEventListener(MouseEvent.CLICK, ValidateAndsearch);
s1.Au.addEventListener(MouseEvent.CLICK, fl_ClickToGoToautomatch);
s1.setting.addEventListener(MouseEvent.CLICK, fl_ClickToGoToss);
s1.Shome.addEventListener(MouseEvent.CLICK, fl_ClickToGoTohom);
// Build the varSend variable
SrSend = new URLRequest("http://localhost/search.php");
SrSend.method = URLRequestMethod.POST;
Arvariables = new URLVariables;
SrSend.data = Arvariables;
SaLoader = new URLLoader();
SaLoader.dataFormat = URLLoaderDataFormat.TEXT;
SaLoader.addEventListener(Event.COMPLETE,Asandler);
// private methods
function Asandler(event:Event):void{
// retrieve data from php call
var resultString :String = event.target.data;
// parse result string as json object and cast it to array
var resultArray :Array = JSON.parse( resultString ) as Array;
// get the length of the result set
var len:int = resultArray.length;
// create vector of SearchVO
var searchVOs:Vector.<searchVO1> = new Vector.<searchVO1>();
// loop the result array
var i:int;
for(i=0; i<len; i++ )
{
searchVOs[i] = new searchVO1();
searchVOs[i].nobed = resultArray[i].nobed;
searchVOs[i].zip = resultArray[i].zip;
searchVOs[i].Location = resultArray[i].Location;
searchVOs[i].price = resultArray[i].price;
}
// call a function to create your boxes
// or maybe create your SearchVector class and pass it your search vector
var mySearchVector:SearchVectorTest = new SearchVectorTest(searchVOs);
addChild(mySearchVector);
}
}
}
public function searchVOs( nobed:String, zip:String, location:String, price:String )
{
this.nobed = nobed;
this.zip = zip;
this.Location = Location;
this.price = price;
}
public function ValidateAndsearch (event:MouseEvent):void {
// validate fields
Arvariables.nobed = s1.nobed.text;
Arvariables.zip = s1.zip.text;
Arvariables.Location = s1.Location.text;
Arvariables.price = s1.price.text;
SaLoader.load(SrSend);
var s7:sresultnologin = new sresultnologin()
removeChild(s1);
addChild(s7);
}
// close else condition for error handling
// close validate and send function
private function fl_ClickToGoToautomatch(event:MouseEvent):void
{
var s7:Auto = new Auto ();
removeChild(s1);
addChild(s7);
}
private function fl_ClickToGoToss(event:MouseEvent):void
{
//
}
private function fl_ClickToGoToaccount(event:MouseEvent):void
{
var s7:Account = new Account ();
removeChild(s1);
addChild(s7);
}
private function fl_ClickToGoTohom(event:MouseEvent):void
{
var s7:homepage = new homepage ();
removeChild(s1);
addChild(s7);
}
}
}
i think you have to remove these lines:
public var Bolder:MovieClip;
public var Listing2:MovieClip;
and try to get your Listing2 object like this:
var newListing:Listing2 = s3.getChildAt(0);
but if you want to access your listings in the SearchVectorTest class it's better to keep a public reference of them like this (maybe in an array or a vector):
SearchVectortest class:
public class SearchVectorTest extends MovieClip
{
/** the array of listings **/
public var listings:Vector.<Listing2>;
public function SearchVectorTest(test:Vector.<searchVO1>)
{
// put the array length in a variable -> if test = null make len = 0
var len:int = test ? test.length : 0;
// create your vector for your listings with the len size
listings = new Vector.<Listing2>(len, true);
// ...
for( var k:int = 0; k < len; k++ )
{
var bolder:Listing2 = new Listing2();
bolder.mouseChildren = false; // ignore children mouseEvents
bolder.mouseEnabled = true; // enable mouse on the object - normally set to true by default
bolder.useHandCursor = true; // add hand cursor on mouse over
bolder.buttonMode = true; // this must be set to true to have hand cursor
// add your linsting to the vector
listings[k] = bolder;
//...
}
// ...
}
}
after that you could get your listing like this:
sresultnologin.as
public class sresultnologin extends MovieClip
{
public var s1 :Searchreult = new Searchreult ();
//public var Bolder :MovieClip; // never used -> useless
//public var Listing2 :MovieClip; // never used -> useless
public function sresultnologin()
{
// init
addEventListener(Event.ADDED_TO_STAGE, onadded);
function onadded (event:Event):void
{
s1.x=-10;
s1.y=10;
addChild(s1);
}
var s3:SearchVectorTest= new SearchVectorTest(new Vector.<searchVO1>);
addChild (s3);
s1.SRhome.addEventListener(MouseEvent.CLICK, fl_ClickToGoTol);
s1.ARsearch.addEventListener(MouseEvent.CLICK, fl_ClickToGosearch);
// verify if there are enties in the array
if( s3.listings.length > 0 )
{
// get the first listing in the listing array
var newListing:Listing2 = s3.listings[0];
newListing.addEventListener(MouseEvent.CLICK, goto);
}
else
{
// do something if there are no results
}
}
//...
}
hope that helps ;)

Access of undefined property- but its defined.

I get that error message for all lines of choosetext()- which is referred every time I change the value of mode.
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.;
import flash.ui.Keyboard;
//import board;
import flash.accessibility.AccessibilityImplementation;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.text.AntiAliasType;
import flash.utils.describeType;
import flash.net.;
import Set;
import StatusBox;
import Statusx;
import flash.display.InteractiveObject;
import flash.text.TextFieldType;
import flash.events.FocusEvent;
import fl.managers.FocusManager;
import flash.display.*;
import flash.display.Stage;
import flash.events.KeyboardEvent;
public class boxsprite extends Sprite
{
[Embed(source = "C:/Windows/Fonts/Verdana.ttf", fontName = "Verdana", fontWeight = "bold", advancedAntiAliasing = "true", mimeType = "application/x-font")]
public static const VERD:Class;
[Embed(source="../lib/box.gif")]
private var boxspriteClass:Class
[Embed(source = "../lib/m2.gif")]
private var m2:Class
[Embed(source = "../lib/m3.gif")]
private var m3:Class
[Embed(source="../lib/m4.gif")]
private var m4:Class
[Embed(source = "../lib/m5.gif")]
private var m5:Class
[Embed(source = "../lib/m6.gif")]
private var m6:Class
[Embed(source = "../lib/m7.gif")]
private var m7: Class
[Embed(source="../lib/m8.gif")]
private var m8: Class
[Embed(source = "../lib/m9.gif")]
private var m9: Class
internal var mode:uint=1;
internal var displaytext:String;
internal var setBox:Boolean = false;
internal var onBoard:Array = [0];
internal var playerRound:uint = 1;
internal var round:uint = 1;
internal var playernumber:uint;
internal var myTextBox:TextField = new TextField();
public function boxsprite():void
{
trace (mode);
init2();
var boxsprite2:Bitmap = new boxspriteClass() as Bitmap;
this.addChild(boxsprite2);
var m77:Bitmap = new m7 as Bitmap;
this.addChild(m77)
var m66:Bitmap = new m6 as Bitmap;
this.addChild(m66)
var m55:Bitmap = new m5 as Bitmap;
this.addChild(m55)
var m44:Bitmap = new m4 as Bitmap;
this.addChild(m44)
var m33:Bitmap = new m3 as Bitmap;
this.addChild(m33);
var m22:Bitmap = new m2 as Bitmap;
this.addChild(m22)
}
private function choosetext():void
{ switch (mode)
{
case 2: {this.setChildIndex(m22, this.numChildren - 1);}
case 3: {this.setChildIndex(m33, this.numChildren - 1);}
case 4: {this.setChildIndex(m44, this.numChildren - 1);}
case 5: {this.setChildIndex(m55, this.numChildren - 1);}
case 6: {this.setChildIndex(m66, this.numChildren - 1);}
case 7: {this.setChildIndex(m77, this.numChildren - 1); }
case 8: {this.setChildIndex(m88, this.numChildren - 1); }
case 9: {this.setChildIndex(m99, this.numChildren - 1); }
}
}
Try to define m22,m33...m99 as class variable, not in the boxsprite function
public class boxsprite extends Sprite
{
private var m22:Bitmap;
public function boxsprite():void {
m22= new m2 as Bitmap;
}
}

Child object not detected

Why can't it detect these declared image objects- m22,m33....?
TypeError: 2007 Error #: Parameter child must be non-null.
The code runs fine until choosetext function then errors.
mode traces display.
Other traces display.
Yaddah Yaddah
boxtrans is a transparent sprite to mask mouse input.
package {
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.*;
import flash.ui.Keyboard;
import mx.core.BitmapAsset;
//import board;
import flash.accessibility.AccessibilityImplementation;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.text.AntiAliasType;
import flash.utils.describeType;
import flash.net.*;
import Set;
import StatusBox;
import Statusx;
import flash.display.InteractiveObject;
import flash.text.TextFieldType;
import flash.events.FocusEvent;
import fl.managers.FocusManager;
import flash.display.*;
import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.utils.*;
import boxtrans;
public class boxsprite extends Sprite {
[Embed(source = "C:/Windows/Fonts/Verdana.ttf", fontName = "Verdana", fontWeight = "bold", advancedAntiAliasing = "true", mimeType = "application/x-font")]
public static const VERD:Class;
[Embed(source="../lib/box.gif")]
private var boxspriteClass:Class
[Embed(source = "../lib/m2.gif")]
private var m2:Class
[Embed(source = "../lib/m3.gif")]
private var m3:Class
[Embed(source="../lib/m4.gif")]
private var m4:Class
[Embed(source = "../lib/m5.gif")]
private var m5:Class
[Embed(source = "../lib/m6.gif")]
private var m6:Class
[Embed(source = "../lib/m7.gif")]
private var m7: Class
[Embed(source="../lib/m8.gif")]
private var m8: Class
[Embed(source = "../lib/m9.gif")]
private var m9: Class
internal var m22:Bitmap;
internal var m33:Bitmap;
internal var m44:Bitmap;
internal var m55:Bitmap;
internal var m66:Bitmap;
internal var m77:Bitmap;
internal var m88:Bitmap;
internal var m99:Bitmap;
internal var boxsprite2:Bitmap;
internal var boxtrans1:Sprite;
internal var mode:uint=2;
internal var displaytext:String;
internal var setBox:Boolean = false;
internal var onBoard:Array = [0];
internal var playerRound:uint = 1;
internal var round:uint = 1;
internal var playernumber:uint;
internal var myTextBox:TextField = new TextField();
public function boxsprite():void {
init();
}
internal function init():void {
boxsprite2=new boxspriteClass as Bitmap;
this.addChild(boxsprite2);
m77= new m7 as Bitmap;
this.addChild(m77);
m66= new m6 as Bitmap;
this.addChild(m66);
m55= new m5 as Bitmap;
this.addChild(m55);
m44= new m4 as Bitmap;
this.addChild(m44);
m33= new m3 as Bitmap;
this.addChild(m33);
m22 = new m2 as Bitmap;
this.addChild(m22);
boxtrans1 = new boxtrans() as Sprite;
boxtrans1.x = 0;
boxtrans1.y = 240;
this.addChild(boxtrans1);
this.addEventListener(MouseEvent.CLICK, clickDoubleClick);
}
internal var m_nDoubleClickSpeed:Number = 300;
internal var m_toMouse:Number;
internal function clickDoubleClick(e:MouseEvent):void {
if (isNaN(m_toMouse)==false) {
clearTimeout(m_toMouse);
HandleDoubleClick();
} else {
m_toMouse = setTimeout(HandleSingleClick, m_nDoubleClickSpeed);
}
}
internal function HandleSingleClick():void {
trace("HandleSingleClick");
m_toMouse = NaN;
}
internal function HandleDoubleClick():void {
modeswitch();
trace("HandleDoubleClick");
m_toMouse = NaN;
}
internal function modeswitch():void{
trace(mode);
switch(mode) {
case 8:
{mode = 9;
choosetext(); }
case 9:
{mode = 2;
choosetext();
}
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
{mode +=1;
choosetext(); }
}
}
internal function choosetext():void {
switch (mode) {
case 2: {this.setChildIndex(m22,this.numChildren - 1);}
case 3: {this.setChildIndex(m33,this.numChildren - 1);}
case 4: {this.setChildIndex(m44,this.numChildren - 1);}
case 5: {this.setChildIndex(m55,this.numChildren - 1);}
case 6: {this.setChildIndex(m66,this.numChildren - 1);}
case 7: {this.setChildIndex(m77,this.numChildren - 1);}
case 8: {this.setChildIndex(m88,this.numChildren - 1);}
case 9: {this.setChildIndex(m99,this.numChildren - 1); }
}
}
}
}
It looks like you are not instantiating m88 or m99 anywhere.
Since you don't have any breakcommands in your switch statement it falls through and executes every case even if mode is only 2.
I'm assuming you meant to do something like this:
switch (mode) {
case 2:
this.setChildIndex(m22,this.numChildren - 1);
break;
case 3:
this.setChildIndex(m33,this.numChildren - 1);
break;
// etc...
}

Upload picture directly to the server

In the following link http://www.tuttoaster.com/create-a-camera-application-in-flash-using-actionscript-3/ how to make the picture upload directly to the server after taking a picture from webcam
package
{
import flash.display.Sprite;
import flash.media.Camera;
import flash.media.Video;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.utils.ByteArray;
import com.adobe.images.JPGEncoder;
public class caml extends Sprite
{
private var camera:Camera = Camera.getCamera();
private var video:Video = new Video();
private var bmd:BitmapData = new BitmapData(320,240);
private var bmp:Bitmap;
private var fileReference:FileReference = new FileReference();
private var byteArray:ByteArray;
private var jpg:JPGEncoder = new JPGEncoder();
public function caml()
{
saveButton.visible = false;
discardButton.visible = false;
saveButton.addEventListener(MouseEvent.MOUSE_UP, saveImage);
discardButton.addEventListener(MouseEvent.MOUSE_UP, discard);
capture.addEventListener(MouseEvent.MOUSE_UP, captureImage);
if (camera != null)
{
video.smoothing = true;
video.attachCamera(camera);
video.x = 140;
video.y = 40;
addChild(video);
}
else
{
trace("No Camera Detected");
}
}
private function captureImage(e:MouseEvent):void
{
bmd.draw(video);
bmp = new Bitmap(bmd);
bmp.x = 140;
bmp.y = 40;
addChild(bmp);
capture.visible = false;
saveButton.visible = true;
discardButton.visible = true;
}
private function saveImage(e:MouseEvent):void
{
byteArray = jpg.encode(bmd);
fileReference.save(byteArray, "Image.jpg");
removeChild(bmp);
saveButton.visible = false;
discardButton.visible = false;
capture.visible = true;
}
private function discard(e:MouseEvent):void
{
removeChild(bmp);
saveButton.visible = false;
discardButton.visible = false;
capture.visible = true;
}
}
}
The FileReference.upload() and FileReference.download() functions are nonblocking. These functions return after they are called, before the file transmission is complete. In addition, if the FileReference object goes out of scope, any upload or download that has not yet been completed on that object is cancelled upon leaving the scope. So, be sure that your FileReference object will remain in scope for as long as the upload or download could be expected to continue. http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001063.html