AS3 - Error #1010: A term is undefined and has no properties - actionscript-3

I keep getting the following error:
TypeError: Error #1010: A term is undefined and has no properties. at
FinalGame_fla::MainTimeline/pulse()
[FinalGame_fla.MainTimeline::frame1:183]
I have checked the code multiple times and can't seem to figure out what is wrong because the high score table still displays the correct entries.
Below is the code showing the variables defined and the code itself which is causing the problem.
Defining Variables & Arrays
var playerName:String="Anonymous";
var allScores:Array = new Array();
var nameBoxes:Array = new Array(mcScoreboard.player1, mcScoreboard.player2, mcScoreboard.player3, mcScoreboard.player4, mcScoreboard.player5);
var scoreBoxes:Array = new Array(mcScoreboard.score1, mcScoreboard.score2, mcScoreboard.score3, mcScoreboard.score4, mcScoreboard.score5);
var sr:SharedObject=SharedObject.getLocal("previousResults");
if (sr.data.allScores!=undefined)
{
allScores = sr.data.allScores;
}
Function for displaying high scores
if (livesLeft==0)
{
stopGame();
mcScoreboard.visible=true;
var playerScore:Object = new Object();
playerScore["name"] = playerName;
playerScore["score"] = totalScore;
allScores.push(playerScore);
sr.data.allScores = allScores;
sr.flush();
allScores.sortOn("score", Array.DESCENDING|Array.NUMERIC);
for (var i=0;i<allScores.length;i++)
{
var obj:Object = allScores[i];
*nameBoxes[i].text = obj["name"];*
scoreBoxes[i].text = obj["score"];
}
}
Flash says the line displayed second-to-last is causing the problem. But all variables and arrays have been declared appropriately so I do not understand where I am going wrong.

Related

AS3 Referencing an object or variable via string etc

I have found answers 'similar' to the one I'm looking for. I really hope I didn't overlook an already answered problem.
code:
var Randy:Object = {age:32, gender:1};
var Joey:Object = {age:35, gender:1};
var slot_0 = Randy;
var slot_1 = Joey;
myFunction();
function myFunction():void{
for(var i = 0; i < 2; i++){
var thisObject = ("Slot_" + i);
trace(thisObject); // example 1
trace(thisObject.age); //example 2
}
}
it will trace in //example 1
slot_0
slot_1
*if I 'trace(thisObject)' the 'name of the Objects' ("slot_0" ; "slot_1") trace out.*
but in //example 2 I get:
Error #1069: Property age not found on String and there is no default value.
*How do I get it to understand that I want it to reference the properties of the object itself? e.g. 'trace(thisObject.age) means slot_0.age witch means Randy.age etc...*
Without a for-loop, I have to write a lot of redundant script, so I need to know this!
Thank You in advance for the help!
var thisObject = this["slot_"+i];
That's how you can do a string reference. Of course, if the var is located elsewhere, use the proper parent object.

How do I dynamically add an object to my Flex 3 Array Collection?

I have thoroughly searched, but have not found an answer to this question. Maybe my question is wrong. I have a total of 30 Children on each Canvas child of my tabNavigator. The code works well for counting and iterating through the children, but when I attempt to add an item to my ArrayCollection, it all falls apart. Here's the code:
private function addrNewDB():void {
var q:int = 0;
var t:int = tabNavigator.numChildren;
while (q<t){
var TNG:Array = tabNavigator.getChildren();
var qnn:Array = TNG[q].getChildren() as Array;
var gat:int = 0;
var pat:int = TNG[q].numChildren;
var newItem:Object = new Object();
while (gat<pat){
if (UIComponent(qunn[gat]) is CheckBox){
if (qunn[gat].selected == true){
var game:String = "Y";
}
else {
gm = "N";
}
Alert.show("gat: "+String(gat)+" | pat: "+String(pat)+"\n"+qnn[gat].id+" - "+qnn[gat].label+": "+gm);
}
gat++;
}
q++;
}
}
What's going on here is that I have tabs that are dynamically added at runtime with a button. Each tab has a canvas upon which are textboxes, labels, checkboxes, and a combobox. There are 30 items in total; seven of them are checkboxes.
I have set up this code to iterate through each child (component) of each Canvas child (pat) of each Tab(t) in my tabNavigator, determine if the component is a CheckBox, see if it is selected, and then Alert me for only the 7 CheckBoxes on each Canvas.
All of this works well. Where I run into a snag is when I attempt to add the new item to the HardwareItems ArrayCollection.
I think that I am just not getting the syntax right. When I try to place some code to add a new item to HardwareItems right after the Alert, it stops Alerting me after the first CheckBox, so I am assuming that it is running into an issue of some kind with the way I've been coding it.
What I would like is some help in correctly adding a new item to the HardwareItems array collection for each of the 7 checkboxes.
I have tried this:
HardwareItems.addItem({merch: lblMerchID.text,
item: qnn(gat).label,
manf: "",
have: gm,
requ: "",
qual: "",
location: "",
id: qnn(gat).id});
and this:
newItem['merch'] = lblMerchID.text;
newItem['item'] = qnn(gat).label;
newItem['qual' = "";
newItem['loc'] = "";
newItem['id'] = qnn(gat).id;
HardwareItems.addItem(newItem);
HardwareItems.refresh();
and this too:
newItem.merch = lblMerchID.text;
newItem.item = qnn(gat).label;
newItem.qual = "";
newItem.loc = "";
newItem.id = qnn(gat).id;
HardwareItems.addItem(newItem);
HardwareItems.refresh();
It's obvious that these are all incorrect ways to accomplish what I want, but I'm just trying anything. Incidentally, none of these coding atrocities threw any errors. When I tried them, though, I got one alert... the first CheckBox which is at 23 out of 30 items.
I've read up on all the documentation about ArrayCollection and Array syntax, and I guess I just don't get it. Any help is appreciated. Thank you.
addItem() method should work anyway.
Please, make sure that you:
initialize collection before filling it out:
HardwareItems = new ArrayCollection();
initialize objects before filling it out:
newItem = {};
Anyway, remember, that ArrayCollection has a property 'source', which is actually an array.
So, instead of addItem you may use the push() method as following:
var HardwareItems:ArrayCollection = new ArrayCollection();
var newItem:Object = {};
newItem['merch'] = lblMerchID.text;
newItem['item'] = qnn(gat).label;
newItem['qual' = "";
newItem['loc'] = "";
newItem['id'] = qnn(gat).id;
HardwareItems.source.push(newItem);
HardwareItems.refresh();

How to use a variable as part of an URL

I have a variable
var qstAccessCode:String = "default";
and a loader with URLRequest
var qst:XML;
var qstLoader:URLLoader = new URLLoader();
qstLoader.load(new URLRequest("http://dl.dropbox.com/u/44181313/Qaaps/Audio/" + qstAccessCode + ".qst"));
qstLoader.addEventListener(Event.COMPLETE, processQST);
function processQST(e:Event):void {
qst = new XML(e.target.data);
trace("QST loading");
}
I would like to use the value of qstAccessCode to complete the URL (so I can change the URL based on user input - if no input then use "default") but I get an error:
"1120: Access of undefined property qstAccessCode"
Is this to do with scoping? How can I complete the URL? Thanks in advance.
Edit: I haven't been able to get clear on this, so I'm also going to look at generating the complete URL from the user-input function and see if I get the URLRequest to pick it up as a variable. If there are any further comments on the original idea I will be very grateful to read them. Cheers.
Edit: #Moorthy I have qstAccessCode defined like this:
var qatAccessCode:String = "default";
var stageText:StageText = new StageText();
stageText.returnKeyLabel = ReturnKeyLabel.GO;
stageText.stage = this.stage;
stageText.viewPort = new Rectangle(225, 765, 200, 35 );
stageText.addEventListener(Event.CHANGE, onChange);
function onChange(e:Event):void
{
qatAccessCode = stageText.text;
trace(qatAccessCode);
}
It traces keyboard entry when I test movie (Air 3.2 for Android).
qstAccessCode should be defined in the same scope as the URLRequest.
You must defined property qstAccessCode like:
var qstAccessCode:string;
qstAccessCode's value is your url address.

How to assign URLVariables result to a String Variable?

In the following example (yes, I am coding on my timeline while I try to work this out - I know, I know) I am loading an SWF in an HTML page and then directing the SWF to get the query parameters from the current URL. The query parameter will contain the source for the video to play.
This seems straight forward to me but I cannot get myURL = urlVars.videoloc; to work. More specifically, urlVars.videoloc seems to be undefined rather than holding the query parameter from the URL. All other variables are correct; both wholeURL and urlVars are defined.
//Initialize Global Event Listener
player.addEventListener(Event.ADDED_TO_STAGE, getPlay, false, 0, true);
//Function to play the video
function getPlay(e:Event):void {
var wholeURL:String = ExternalInterface.call("window.location.search.toString");
var urlVars:URLVariables = new URLVariables(wholeURL);
var myURL:String = urlVars.videoloc; //<--- Trouble, returning 'undefined'
errorBox.text = "videoloc="+urlVars.videoloc+"\nwholeURL="+wholeURL+"\nurlVars="+urlVars+"\nmyURL="+myURL; //<--- The reason I know it is returning 'undefined'
if (myURL) {
player.load(myURL);
player.play();
}
}
Ideally you should use a debugger to inspect the makeup of your URLVariables object.
If you're unable to do things the easy way, you could do this to trace its contents:
for (var parameter:String in urlVars) {
trace(parameter + "=" + urlVars[parameter]);
}
As you can see, you can step through every parameter inside urlVars using a for in loop.
I'm guessing videoLoc is your first parameter? Look at the results of this test of mine:
var address:String = "http://www.google.ca/search?q=test&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a";
var urlVars:URLVariables = new URLVariables(address);
for (var parameter:String in urlVars) {
trace(parameter + "=" + urlVars[parameter]);
}
The output of this is:
aq=t
rls=org.mozilla:en-GB:official
client=firefox-a
http://www.google.ca/search?q=test
ie=utf-8
oe=utf-8
See what happened to the q parameter? To fix this, use only the text past the ?
var address:String = "http://www.google.ca/search?q=test&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a";
var urlVars:URLVariables
= new URLVariables(address.substr(address.indexOf('?')+1));
for (var parameter:String in urlVars) {
trace(parameter + "=" + urlVars[parameter]);
}

(Flash CS4/AS3) Error #1007: Instantiation attempted on a non-constructor

Having a bit of a problem creating an instance of an object. Bear in mind that this is timeline based and NOT an external class…
var foo:Object {
var a:String;
var b:String;
}
var new_foo:Object;
function makeFoo():void
{
new_foo = new foo();
}
function doStuff(e:MouseEvent):void
{
makeFoo();
}
Everything runs fine until the 'new_foo = new foo();' bit, at which point I get the #1007 error.
Any ideas?
the problem is your object. missing some sintax, here is how to declare a object with two empty strings:
var foo:Object = {
a:"",
b:""
}