Upload picture directly to the server - html

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

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.

AS3. How can a global var take a value which appears in a listener Event.COMPLETE

This is my code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.LoaderInfo;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.GradientType;
import flash.sampler.getSize;
public class Miniaturka extends MovieClip {
private var id:String;
public static var miniWidth:Number = 0;
private var tween:Tween;
private var tryb:Boolean;
private var button:Sprite;
private var index:Number;
private var aktywna:Boolean = false;
public var bLoad:Boolean = false;
public function Miniaturka(id:String,index:Number):void {
this.id = id;
this.index = index;
tryb = false;
var loader:Loader = new Loader();
loader.load(new URLRequest("images/"+id+"m.jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,nLoadComplete);
this.alpha = 1;
button = new Sprite();
button.graphics.beginFill(0x000000,0);
button.graphics.drawRect(0,0,889,500);
button.graphics.endFill();
button.buttonMode = true;
addChild(button);
button.addEventListener(MouseEvent.MOUSE_OVER,onOver);
button.addEventListener(MouseEvent.MOUSE_OUT,onOut);
button.addEventListener(MouseEvent.CLICK,onClick);
}
private function nLoadComplete(event:Event):void {
var loader:Loader = new Loader();
loader = LoaderInfo(event.target).loader;
pusty.addChild(loader);
ladowanie.visible = false;
tween = new Tween(pusty,"alpha",Regular.easeOut,0,0.6,2,true);
bLoad = true;
setStan(false);
miniWidth = loader.width;
pusty.alpha = 0;
}
private function onOver(event:MouseEvent):void {
if (!aktywna) {
setStan(true);
}
}
private function onOut(event:MouseEvent):void {
if (!aktywna) {
setStan(false);
}
}
private function onClick(event:MouseEvent):void {
aktywuj();
}
public function deaktywuj():void {
setStan(false);
aktywna = false;
}
public function aktywuj():void {
MovieClip(parent).deaktywuj();
aktywna = true;
setStan(true);
MovieClip(parent.parent).loadBig(id,index);
}
private function setStan(tryb:Boolean):void {
this.tryb = tryb;
if (tryb) {
pusty.alpha = 1;
} else {
pusty.alpha = 0.6;
}
}
}
}
I want to create a gallery, and this is a code of a class which loads jpg. files with different widths, but the same height.
My problem is that I want to make the public static var miniWidth which takes the value: loader.width in function: nLoadComplete, take that value as a global var, and put it in the line: button.graphics.drawRect(0,0,889,500); so it would look like button.graphics.drawRect(0,0,miniWidth ,500);
This will create a button(rectangle) the same height and width as the loaded jpg. but i can't figure it out... How can I do that?
Wait for the image to load before drawing your shape. In the example below, I've only reprinted the affected functions.
private function Miniaturka(id:String, index:Number):void {
this.id = id;
this.index = index;
tryb = false;
var loader:Loader = new Loader();
loader.load(new URLRequest("images/" + id + "m.jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, nLoadComplete);
this.alpha = 1;
}
private function nLoadComplete(event:Event):void {
var loader:Loader = new Loader();
loader = LoaderInfo(event.target).loader;
pusty.addChild(loader);
ladowanie.visible = false;
tween = new Tween(pusty, "alpha", Regular.easeOut, 0, 0.6, 2, true);
bLoad = true;
setStan(false);
miniWidth = loader.width;
pusty.alpha = 0;
createBtn();
}
private function createBtn():void {
button = new Sprite();
button.graphics.beginFill(0x000000, 0);
button.graphics.drawRect(0, 0, miniWidth, 500);
button.graphics.endFill();
button.buttonMode = true;
addChild(button);
button.addEventListener(MouseEvent.MOUSE_OVER, onOver);
button.addEventListener(MouseEvent.MOUSE_OUT, onOut);
button.addEventListener(MouseEvent.CLICK, onClick);
}

Webcam shows mirror image using action script

Using Flash CS5.5 and action script 3 I have made a small application for image capturing through web cam and integrated it in php page working perfect also save image. But problem is it shows MIRROR image on screen means if I move my right hand on screen it shows left hand. My query is how can I correct this setting. Here is the code -
package take_picture_fla
{
import com.adobe.images.*;
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import flash.ui.*;
import flash.utils.*;
dynamic public class MainTimeline extends MovieClip
{
public var capture_mc:MovieClip;
public var bitmap:Bitmap;
public var rightClickMenu:ContextMenu;
public var snd:Sound;
public var video:Video;
public var bitmapData:BitmapData;
public var warn:MovieClip;
public var save_mc:MovieClip;
public var bandwidth:int;
public var copyright:ContextMenuItem;
public var cam:Camera;
public var quality:int;
public function MainTimeline()
{
addFrameScript(0, frame1);
return;
}// end function
public function onSaveJPG(event:Event) : void
{
var myEncoder:JPGEncoder;
var byteArray:ByteArray;
var header:URLRequestHeader;
var saveJPG:URLRequest;
var urlLoader:URLLoader;
var sendComplete:Function;
var e:* = event;
sendComplete = function (event:Event) : void
{
warn.visible = true;
addChild(warn);
warn.addEventListener(MouseEvent.MOUSE_DOWN, warnDown);
warn.buttonMode = true;
return;
}// end function
;
myEncoder = new JPGEncoder(100);
byteArray = myEncoder.encode(bitmapData);
header = new URLRequestHeader("Content-type", "application/octet-stream");
saveJPG = new URLRequest("save.php");
saveJPG.requestHeaders.push(header);
saveJPG.method = URLRequestMethod.POST;
saveJPG.data = byteArray;
urlLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, sendComplete);
urlLoader.load(saveJPG);
return;
}// end function
public function warnDown(event:MouseEvent) : void
{
navigateToURL(new URLRequest("images/"), "_blank");
warn.visible = false;
return;
}// end function
function frame1()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
rightClickMenu = new ContextMenu();
copyright = new ContextMenuItem("Developed By www.webinfopedia.com Go to Application");
copyright.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, myLink);
copyright.separatorBefore = false;
rightClickMenu.hideBuiltInItems();
rightClickMenu.customItems.push(copyright);
this.contextMenu = rightClickMenu;
snd = new camerasound();
bandwidth = 0;
quality = 100;
cam = Camera.getCamera();
cam.setQuality(bandwidth, quality);
cam.setMode(320, 240, 30, false);
video = new Video();
video.attachCamera(cam);
video.x = 20;
video.y = 20;
addChild(video);
bitmapData = new BitmapData(video.width, video.height);
bitmap = new Bitmap(bitmapData);
bitmap.x = 360;
bitmap.y = 20;
addChild(bitmap);
capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK, captureImage);
save_mc.alpha = 0.5;
warn.visible = false;
return;
}// end function
public function captureImage(event:MouseEvent) : void
{
snd.play();
bitmapData.draw(video);
save_mc.buttonMode = true;
save_mc.addEventListener(MouseEvent.CLICK, onSaveJPG);
save_mc.alpha = 1;
return;
}// end function
public function myLink(event:Event)
{
navigateToURL(new URLRequest("http://www.webinfopedia.com/export-database-data-to-excel-in-php.html"), "_blank");
return;
}// end function
}
}
You can just use video.scaleX = -1; to mirror the image.
You should check your camera's settings at the system level - it is possible that the device driver is set to mirror the image.

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 ;)

3D object in FLARToolKit keep appearing even though there is no marker detected

I have another (newbie) question about FLARToolKit.
This is Lee Brimelow's code to make 3 boxes on top of the marker.
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){}
}
}
the flaw of this code is, after the marker detected, yes, the 3D object got rendered. but after the marker were not detected, the object still appeared on the screen (even though it did not move)
how can I fix this?
you have to change the visible property of the FLARBaseNode in the detection condition
if(detector.detectMarkerLite(raster, 80) && detector.getConfidence() > 0.5){
detector.getTransformMatrix(trans);
container.setTransformMatrix(trans);
container.visible = true;
bre.renderScene(scene, camera, vp);
}else
container.visible = false;