Trouble with Array & TransitionManager - actionscript-3

I need help with my Array function. I am trying to create a headline for a website, but it is only the first letter that is being shown:
This is my code:
import fl.transitions.*;
import fl.transitions.easing.*;
var textArray:Array=["W","e","l","c","o","m","e"];
var tformat:TextFormat = new TextFormat();
tformat.color=0x0000CC;
tformat.font="Arial";
tformat.size=40;
var XPosition:Number=100;
var YPosition:Number=12;
var setPosition:Number=36;
function beginPlacement() {
var textfield:TextField = new TextField();
textfield.text=textArray.shift();
textfield.setTextFormat(tformat);
var clip:MovieClip=new MovieClip ;
clip.addChild(textfield);
clip.x=XPosition;
clip.y=YPosition;
addChild(clip);
var transManager:TransitionManager=new TransitionManager(clip);
transManager.startTransition({type:Photo, direction:Transition.IN, duration:.3, easing:None.easeNone});
transManager.startTransition({type:Zoom, direction:Transition.IN, duration:.3, easing:Elastic.easeOut});
transManager.addEventListener("allTransitionsInDon e", tComplete);
XPosition=+ XPosition+setPosition;
}
function tComplete(e:Event):void {
if (textArray.length>0) {
beginPlacement();
}
}
beginPlacement();

Related

Change the color of object and link the choosen color to the next scene not all the color button

Here is my coding using AS3:
import flash.events.MouseEvent;
import flash.display.MovieClip;
var btts:Array = [red,yellow,blue];
var set_colors:Object = {'red':0xff0000,'yellow':0xffff00,'blue':0x0000ff};
var obj_color:ColorTransform = new ColorTransform();
for(var i:int=0; i<btts.length; i++) {
obj_color.color = set_colors[btts[i].name];
btts[i].transform.colorTransform = obj_color;
btts[i].addEventListener(MouseEvent.CLICK, changeColor);
}
function changeColor(evt:Event):void
{
var b_name = evt.target.name;
obj_color.color = set_colors[b_name];
rec.transform.colorTransform = obj_color;
}
go.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_6);
function fl_ClickToGoToScene_6(event:MouseEvent):void
{
if(obj_color.color == set_colors[red])
{
gotoAndPlay(1, "Scene 2");
}
}
stop();
Hopefully someone can help me to repair this code.This code shown that when i click all the color button it will go to Scene 2 but in my condition,I want only one choosen button will go to Scene 2.
This may help you to deal with the background color and Stage.Resize, but you will need to adapt the code for the Color change...
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
{
private static const ORANGE:int = 0xff9900;
var bg:MovieClip;
var bg_mask:MovieClip;
var marginx:int = 10;
var marginy:int = 10;
var display:MovieClip;
var displayTextField:TextField;
var ellipseWidth:int = 90;
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 + "}");
}
}
}
Just add a function to change the Color, but this is a simple way to do this...
In the method drawBackground, just add the Color that You want...
Just edit the fillColor in drawBackground method...
This will be the same as on http://tatactic.be/stackOverflow/ChangeBG/StageResizeSimple.swf
But You can easiely change the Color too.
[EDIT]
here You may add a function thath will change Your BG color
So this should be a piece of cake... ;)
[/EDIT]
Best regards.
Nicolas.

Why my player can't play video when XML store 2 data in Adobe Air AS3?

I'm making an android app using Adobe AIR AS3. My program works fine and the video can play when I have only 1 data on XML. But when I have 2 or more data, I can't play the video, even when the image loaded just fine. Is there anything that I missed on my program? Here is the entire my AS3 script and my xml data.
import flash.events.MouseEvent;
import flash.media.Video;
import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;
import flash.ui.Mouse;
import flash.media.SoundTransform;
import flash.geom.Rectangle;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
stage.displayState=StageDisplayState.FULL_SCREEN;
FilterShortcuts.init();
stop();
var mainBtn:MovieClip = btnMain;
var helpBtn:MovieClip = btnHelp;
var exitBtn:MovieClip = btnExit;
var mainPage:MovieClip = mcMainMenu;
var logoIcon:MovieClip = mcIcon;
var contentPage:MovieClip = mcContent;
var videoBox:MovieClip = mcContent.mcVideoArea;
var playBtn:MovieClip = mcContent.btnPlay;
var pauseBtn:MovieClip = mcContent.btnPause;
var timelineSlider:MovieClip = mcContent.mcTimelineSlider;
var timelineBuffer:MovieClip = mcContent.mcTimelineSlider.mcTimelineBuffer;
var timelineProgress:MovieClip = mcContent.mcTimelineSlider.mcTimelineProgress;
var timelineBtn:MovieClip = mcContent.mcTimelineSlider.btnTimeline;
var volumeSlider:MovieClip = mcContent.mcVolumeSlider;
var volumeBtn:MovieClip = mcContent.mcVolumeSlider.btnVolume;
var volumeActive:MovieClip = mcContent.mcVolumeSlider.mcVolumeActive;
var helpPage:MovieClip = mcHelpPage;
var backBtn:MovieClip = mcHelpPage.btnCancel;
var exitPage:MovieClip = mcExitPage;
var yesBtn:MovieClip = mcExitPage.btnYes;
var noBtn:MovieClip = mcExitPage.btnNo;
mainPage.visible=true;
logoIcon.visible=true;
contentPage.visible=false;
mainBtn.visible=false;
helpPage.visible=false;
exitPage.visible=false;
var currentVideo:String;
var videoWidth:Number=1280;
var videoHeight:Number=720;
var duration:Number;
var video:Video=new Video(videoWidth, videoHeight);
video.x=-640;
video.y=-360;
videoBox.addChild(video);
var nc:NetConnection=new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
video.attachNetStream(ns);
var newMeta:Object=new Object();
newMeta.onMetaData=onMetaData;
ns.client=newMeta;
ns.bufferTime=5;
var videoSound=SoundTransform;
var volumeBounds:Rectangle;
videoSound=new SoundTransform();
videoSound.volume=.5;
ns.soundTransform=videoSound;
var videoInterval=setInterval(videoStatus, 100);
var amountLoaded:Number;
var scrubInterval;
var mcContainer:MovieClip;
var xmlPath:String="list.xml";
var xml:XML;
var loader=new URLLoader();
var currentThumb:Number=0;
var i:Number=0;
var videoThumbLoader:Loader;
var videoItemName:String;
var columns:Number=6;
var xCount:Number;
var yCount:Number;
mainBtn.addEventListener(MouseEvent.CLICK, gotoMain);
helpBtn.addEventListener(MouseEvent.CLICK, gotoHelp);
exitBtn.addEventListener(MouseEvent.CLICK, gotoExit);
backBtn.addEventListener(MouseEvent.CLICK, goBack);
yesBtn.addEventListener(MouseEvent.CLICK, exitApp);
noBtn.addEventListener(MouseEvent.CLICK, goBack);
ns.addEventListener(NetStatusEvent.NET_STATUS, myStatusHandler);
playBtn.addEventListener(MouseEvent.CLICK,playBtnClick);
pauseBtn.addEventListener(MouseEvent.CLICK,pauseBtnClick);
volumeBtn.addEventListener(MouseEvent.MOUSE_DOWN,volumeScrubberDown);
timelineBtn.addEventListener(MouseEvent.MOUSE_DOWN, videoScrubberDown);
loader.load(new URLRequest(xmlPath));
loader.addEventListener(Event.COMPLETE,xmlLoaded);
function gotoMain(e:MouseEvent):void{
mainPage.visible=true;
logoIcon.visible=true;
contentPage.visible=false;
mainBtn.visible=false;
flash.media.SoundMixer.stopAll();
}
function gotoHelp(e:MouseEvent):void{
helpPage.visible=true;
ns.pause();
}
function goBack(e:MouseEvent):void{
helpPage.visible=false;
exitPage.visible=false;
ns.resume();
}
function gotoExit(e:MouseEvent):void{
helpPage.visible=false;
exitPage.visible=true;
ns.pause();
}
function exitApp(e:MouseEvent):void{
NativeApplication.nativeApplication.exit();
}
function myStatusHandler(e:NetStatusEvent):void{
//trace(e.info.code);
switch(e.info.code){
case "NetStream.Buffer.Full":
ns.bufferTime=10;
break;
case "NetStream.Buffer.Empty":
ns.bufferTime=10;
break;
case "NetStream.Play.Start":
ns.bufferTime=10;
break;
case "NetStream.Seek.Notify":
ns.bufferTime=10;
break;
case "NetStream.Seek.InvalidTime":
ns.bufferTime=10;
break;
case "NetStream.Play.Stop":
ns.pause();
ns.seek(1);
break;
}
}
function onMetaData(newMeta:Object):void{
//trace("Metadata:duration="+newMeta.duration+" width="+newMeta.width+" height="+newMeta.height+" framerate"+newMeta.framerate);
duration=newMeta.duration;
}
function playBtnClick(e:MouseEvent):void{
ns.resume();
}
function pauseBtnClick(e:MouseEvent):void{
ns.pause();
}
function volumeScrubberDown(e:MouseEvent):void{
volumeBounds=new Rectangle(0,0,169,0);
volumeBtn.startDrag(false,volumeBounds);
stage.addEventListener(MouseEvent.MOUSE_UP,volumeBtnUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE,volumeBtnMove);
}
function volumeBtnUp(e:MouseEvent):void{
volumeBtn.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, volumeBtnUp);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, volumeBtnMove);
}
function volumeBtnMove(e:MouseEvent):void{
volumeActive.width=volumeBtn.x;
videoSound.volume=(volumeBtn.x)/50;
ns.soundTransform=videoSound;
}
function videoStatus():void{
amountLoaded=ns.bytesLoaded/ns.bytesTotal;
timelineBuffer.width=amountLoaded*900;
timelineBtn.x=ns.time/duration*900;
timelineProgress.width=timelineBtn.x;
}
function videoScrubberDown(e:MouseEvent):void{
var bounds:Rectangle=new Rectangle(0,0,900,0);
clearInterval(videoInterval);
scrubInterval=setInterval(scrubTimeline,10);
timelineBtn.startDrag(false,bounds);
stage.addEventListener(MouseEvent.MOUSE_UP,stopScrubbingVideo);
}
function scrubTimeline():void{
ns.seek(Math.floor((timelineBtn.x/900)*duration));
}
function stopScrubbingVideo(e:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_UP,stopScrubbingVideo);
clearInterval(scrubInterval);
videoInterval=setInterval(videoStatus,100);
timelineBtn.stopDrag();
}
function xmlLoaded(e:Event):void{
if((e.target as URLLoader)!=null){
xml = new XML(loader.data);
loader.removeEventListener(Event.COMPLETE, xmlLoaded);
makeVideoThumb();
//trace(xml);
}
}
function makeVideoThumb():void{
xCount=0;
yCount=0;
mcContainer=new MovieClip();
mcContainer.x=-600; //set the container x position
mcContainer.y=-255; //set the container y position
mainPage.addChild(mcContainer);
if(i>0){
i=0;
}
for each(var videoNode:XML in xml.content){
var videoItem:mc_thumbContainer=new mc_thumbContainer();
videoItem.txtVideoTitle.text=videoNode.#title;
videoItem.txtVideoCountry.text=videoNode.#country;
videoItem.x=(videoItem.width+30)*xCount;
videoItem.y=(videoItem.height+30)*yCount;
videoItem.name=""+i;
videoItem.addEventListener(MouseEvent.CLICK, videoItemClick);
var videoThumbURL=videoNode.#cover;
videoThumbLoader=new Loader();
videoThumbLoader.load(new URLRequest(videoThumbURL));
videoThumbLoader.x=6;
videoThumbLoader.y=5;
videoItem.addChild(videoThumbLoader);
videoThumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, videoThumbLoaded);
mcContainer.addChild(videoItem);
i++;
if(xCount+1<columns){
xCount++;
}else{
xCount=0;
yCount++;
}
}
}
function videoThumbLoaded(e:Event):void{
videoThumbLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, videoThumbLoaded);
}
function videoItemClick(e:MouseEvent):void{
videoItemName=e.target.name;
currentVideo=xml.content.#video;
mainPage.visible=false;
logoIcon.visible=false;
contentPage.visible=true;
mainBtn.visible=true;
video.width=videoWidth;
video.height=videoHeight;
ns.play(currentVideo);
}
And here is the xml
<?xml version="1.0"?>
<list>
<content id="1" title="story" country="England" cover="http://localhost:280/list//content/cover/6a778-cover-72.jpg" video="http://localhost:280/list//content/video/e27f9-video.mp4"/>
<content id="2" title="story-2" country="England" cover="http://localhost:280/list//content/cover/2e383-cover-72.jpg" video="http://localhost:280/list//content/video/cce76-video.mp4"/>
</list>

Generating Random text on Collision AS3

I would like to generate some random words when an object hits another one.
I've tried it but only one word comes up and never changes again.
Also would it be better if I make a new class for the random texts or is including it in the Main class good enough? Thanks!
Here's my current code:
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
public class Main extends MovieClip {
public var cell:Cell;
public var group:Array;
public var gameTimer:Timer;
public var score:int = 0;
var array:Array = new Array ("Apples",
"Bananas",
"Grapes",
"Oranges",
"Pineapples"); //create an array of possible strings
var randomIndex:int = Math.random () * array.length;
//public var randomTxt:String;
public function Main() {
group = new Array();
gameTimer = new Timer (25);
gameTimer.addEventListener(TimerEvent.TIMER,moveCell);
gameTimer.start();
}
private function createCell(_x:Number = 0, _y:Number = 0):void {
var cell:Cell = new Cell(_x, _y);
group.push(cell);
addChild(cell);
}
function moveCell (timerEvent:TimerEvent):void {
if (Math.random() < 0.01) {
var randomX:Number = Math.random()*800;
var randomY:Number = Math.random()*600;
createCell(randomX, randomY);
}
for (var i:int = 0; i < group.length; i++)
{
var cell:Cell = Cell(group[i]);
if (cell.hitTestObject(island))
{
cell.parent.removeChild(cell);
group.splice(i,1);
score++;
txtWordDisplay.text = "Killed by" + array [randomIndex];
}
}
scoreOutPut.text = score.toString();
}
}
}
It's always the same word because you only set the randomIndex once at the beginning of your program.
A simple fix would be to update that value when the collision happens:
if (cell.hitTestObject(island))
{
...
randomIndex = Math.floor(Math.random () * array.length);
txtWordDisplay.text = "Killed by" + array [randomIndex];
}

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

Error #1034: Type Coercion failed: cannot convert __AS3__.vec::Vector.<com.clark::searchVO1>$ to __AS3__.vec.Vector.<com.clark::searchVO1>

I want to first start off asking if anyone has any suggestions of any resource(books or examples) on parsing data/or Sessioning variables in AS3. I researched for some resources but those books or sites, does not really cover the topics i mentioned.
I am trying to parse some JSON data from php into AS3 VO, then the VO into Vector file, the Vector File put the data into boxes, and that sits inside another as file for display. The boxes split the results into specific data. For example Box 1(ID1, Name1, Location1). Box 2(ID2,Name2,Location2). When the specific box is hit, the box will session the ID of that Box(listing), then parse it so it goes to the next AS file(to pull out the details from database) to display the details of that specific Listing.
With the help from other post&poster, i managed to get to parsing the JSON back, but i have 2 errors, because i don't know which Valid vector i need to put as the parameter. And can i have some idea/advice on how i should create the "Sessioning ID" when the box is clicked?
Error #1034: Type Coercion failed: cannot convert
AS3.vec::Vector.$ to AS3.vec.Vector..
At this line var s3:SearchVectorTest= new SearchVectorTest(Vector.<searchVO1>); in the file sresultnologin
below.
Error #1069: Property 0 not found on com.clark.SearchVectorTest and there is no default value. Starting from this line
mySearchVector[i].nobed = searchVOs[i].nobed; in the searchVO1 file
below Thanks for your time. 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;
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.searchs.addEventListener(MouseEvent.CLICK, ValidateAndsearch);
// 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
for( var i:int = 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);
for( var i:int = 0; i<len; i++ )
mySearchVector[i].nobed = searchVOs[i].nobed;
mySearchVector[i].zip = searchVOs[i].zip;
mySearchVector[i].Location = searchVOs[i].Location;
mySearchVector[i].price = searchVOs[i].price;
}
}
}
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);
}
}
}
SearchVectorTest
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;
public class SearchVectorTest extends MovieClip
{
public function SearchVectorTest(test:Vector.<searchVO1>)
{
super();
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 currentY:int = 270;
for (var k:int = 0; k < test.length; k++)
{
var Bolder:Listing5 = new Listing5();
Bolder.x=80;
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;
bf1.x = (Bolder.height-bf.height)*.5
bf3.x = (Bolder.height-bf.height)*.5
bf.x = (Bolder.height-bf.height)*.5
bf.y = (Bolder.height-bf.height)*.15
Bolder.addChild(bf);
Bolder.addChild(bf1);
Bolder.addChild(bf2);
Bolder.addChild(bf3);
Bolder.y = currentY;
addChild(Bolder);
currentY += Bolder.height + 35;
}
}
}
}
sresultnologin
package com.clark
{
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
import fl.controls.Button;
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(Vector.<searchVO1>);
addChild (s3);
}
}
}
While your mySearchVector Object isn't added to the display list, all it's content cannot be displayed ...
try it, it must work:
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
for( var i:int = 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;
}
// create your SearchVector class and pass it your search vector
var mySearchVector:SearchVectorTest = new SearchVectorTest(searchVOs);
// add your searchVector to the display list
addChild( mySearchVector );
// REMOVE THIS BLOCK !!
/*
for( var i:int = 0; i<len; i++ )
mySearchVector[i].nobed = searchVOs[i].nobed;
mySearchVector[i].zip = searchVOs[i].zip;
mySearchVector[i].Location = searchVOs[i].Location;
mySearchVector[i].price = searchVOs[i].price;
}
*/
}
var s3:SearchVectorTest= new SearchVectorTest(Vector.<searchVO1>); is you sending a reference to a class not an instance of an object of that type.
Change to either
var s3:SearchVectorTest= new SearchVectorTest(new Vector.<searchVO1>());
or
var s3:SearchVectorTest= new SearchVectorTest(Vector.<searchVO1>([]));