Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-23-2012, 04:05 PM   #1
yogidishman
Registered User
 
Join Date: Jun 2009
Posts: 39
Default Array Question

I am having a problem with an array and 3 strings that I have loaded into it and now want to retrieve and display at certain locations on the stage

I have a 3 element array string and I am loading a string into each element. When a button is pressed I want the elements in the array to display on the stage at specified locations. This should be easy to do but I am getting an error message when I try to specifiy the x,y coordinates of these strings. Here is the error message and my code.

1119: Access of possibly undefined property x through a reference with static type String.

I believe this message is tellling me that I can't position a string element on the stage. If not, how and what must I convert it to in order to place it. ? Thank you.

var myList:Array = new Array("Mario", "Luigi", "Kirby");

var letter1:String
var letter2:String
varl letter3:String

letter1=myList[0]
letter 2=myList[1]
letter 3 = myList[2]

Answer_btn.addEventListener(MouseEvent.CLICK,answe r1);
function answer1(e:MouseEvent):void
{

letter1.x=100
letter1.y=300
letter2.x=200
letter2.y=300
letter3.x=300
letter3.y=300

}
yogidishman is offline   Reply With Quote
Old 07-23-2012, 04:15 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 9,793
Send a message via Skype™ to henke37
Default

A String is not a TextField. The compiler would have caught this error if you had used a vector instead of an array.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 07-23-2012, 05:13 PM   #3
suresh02sd
Registered User
 
Join Date: Jul 2012
Location: Brooklyn, NY
Posts: 34
Default

exactly you need to pay attention to the diffrence between complex variables(objects and such) and primitive variables(numbers, strings...) primitives don't have properties. or in your case you are treating the strings as a movieclip/text field and you can't do that.
suresh02sd is offline   Reply With Quote
Old 07-23-2012, 05:19 PM   #4
yogidishman
Registered User
 
Join Date: Jun 2009
Posts: 39
Default

okay, thanks, but how do I do this then? Do I somehow define these words as something other than string prior to placing them in my array. For example, can I take a string that was entered from a "text" input box, convert it to an object (mc) and then store it so that I can later retrieve it and position it on the stage ?
yogidishman is offline   Reply With Quote
Old 07-23-2012, 05:58 PM   #5
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,888
Default

Where are the named MovieClips in question located, if they are not already on the stage?
ie: Mario Luigi and Kirby

By what mechanism where these MovieClips named?
[afz]snickelfitz is offline   Reply With Quote
Old 07-23-2012, 08:14 PM   #6
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 9,793
Send a message via Skype™ to henke37
Default

You can't "convert" a String to a MovieClip, a String doesn't know anything about MovieClips. Also, Strings are Objects. They are just immutable, like in Java.

Anyway, the important part here is that a String is not an instance of a MovieClip, it isn't a symbol name and it isn't a class name. It is just a String.

You can use Strings to find existing instances in various ways and you can use Strings to look up Classes for use in creating new instances. But they are not the same object.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 07-24-2012, 12:20 AM   #7
thawfeek_yahya
Senior Member
 
thawfeek_yahya's Avatar
 
Join Date: Oct 2009
Location: India
Posts: 124
Send a message via Yahoo to thawfeek_yahya Send a message via Skype™ to thawfeek_yahya
Default

You are trying to access a undefined variable x ie) A String Class does not has property named x. if you are trying to place each string value in a certain place in the stage try this



var letter1:TextField = new TextField();
var letter2:TextField = new TextField();
varl letter3:TextField = new TextField();

letter1.text = "Mario"
letter 2.text = "Luigi"
letter 3.text = "Kirby"

Answer_btn.addEventListener(MouseEvent.CLICK,answe r1);
function answer1(e:MouseEvent):void
{

letter1.x=100
letter1.y=300
letter2.x=200
letter2.y=300
letter3.x=300
letter3.y=300

}
thawfeek_yahya is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:11 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.