Skip to main content
Known Participant
January 21, 2013
Besvarat

list problem

  • January 21, 2013
  • 11 svar
  • 1695 visningar

hi how are you guys ? i hope you all fine ..

here ...

iam trying to make text box as miror for the list object

am gonna explain with images

here

there is 2 frames

first frame

i can enter the name and the price for the item

and when i do that(clicking add item), the item is going to the list object (in the second frame)

but the problem now , is when i try to make a miror for the list in text box it doesn,t work 

i.ve tried to make it string

  

helper = listbox1.selectedIndex

itemname11.text = String(listbox1.getItemAt(helper))

but still displaying it as object

...

here is the full code

package {
import flash.display.MovieClip;
   import flash.events.MouseEvent
   import flash.events.Event;

public class MAIN  extends MovieClip {
  var additemsvar:String
  var addpricevar:int
  var removeitemvar:int
  var itemsnp:Array = new Array (100)
  var itemsinfo:Object = new Object()
  var za:int = 0
  var da:Array = new Array (100)
  var helper:int
  var helper1:String
  var helper2:String
  public function MAIN () {
    addbutton.addEventListener(MouseEvent.CLICK ,addbutton1)
    removebutton.addEventListener(MouseEvent.CLICK ,removebutton1)
    addEventListener(Event.ENTER_FRAME , onEnterFrame)
  addEventListener(Event.ADDED_TO_STAGE,ADDED_TO_STAGE)

  }
  public function ADDED_TO_STAGE (event:Event){
  
   itemsinfo.name1 = new Array()
   itemsinfo.price1 = new Array()
  
  }
  public function onEnterFrame (event:Event){
   helper = listbox1.selectedIndex
   if(listbox1.selectedIndex != -1){
   itemname11.text = String(listbox1.getItemAt(helper))
   }
  
  
  }
 
 
  public function addbutton1 (event:MouseEvent){
  
   additemsvar = additems.text
   addpricevar = int (addprice.text)
  
   listbox2.addItem ({label:itemsnp[za]})
   itemsinfo.name1.push (additemsvar)
   itemsinfo.price1.push (addpricevar)
   listbox1.addItem ({label:(itemsinfo.name1[za])})
   za += 1
  
   for (var zb:String in itemsinfo){
    trace (zb + ":" + itemsinfo[zb])
   
   }
  
   }
  public function removebutton1 (event:MouseEvent){
  
   trace (listbox1.selectedIndex)
  
   listbox1.removeItemAt(listbox1.selectedIndex)
  
  }
  function traceItemsnpF(a:Array):void{

for(var i:int=0;i<a.length;i++){

for(var s:String in a){

trace(s,a+":"+a);

}

}

}

 
}
}

thank you

Det här ämnet har stängts för svar.
Bästa svar av moccamaximum

but still displaying it as object

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/SelectableList.html#getItemAt%28%29

Why should it show as a String when its supposed to return an object?

try:

listbox1.getItemAt(helper).label;

listbox1.getItemAt(helper).data;

then you have access to the strings inside

11 svar

Inspiring
January 21, 2013

but still displaying it as object

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/SelectableList.html#getItemAt%28%29

Why should it show as a String when its supposed to return an object?

try:

listbox1.getItemAt(helper).label;

listbox1.getItemAt(helper).data;

then you have access to the strings inside

Known Participant
January 21, 2013

thank you  a lot mr moccamaximum

it works like that , but i realy dont know why

can you pleases answer these 2 questions

1- "Why should it show as a String when its supposed to return an object" , why return

object?? as i know the text box only takes string values

2- what is the .label , also why we should write it in add item method   , i mean

why it shouldn,t be list.additem(object.text) not  list.additem({label:object.text}) because

in vb works like that

sorry because i asked a lot , but realy this thing confusing me  

thank you again for your help

Inspiring
January 21, 2013

the text box only takes string values

the list juses a DataProvider object to save its data.

It has two public propertys label and data.

This is how its done with the "official" list component in AS3 anyway.

Drag an empty list compoennt from the components panel on stage,

mark it and go to the property/parameter section, then you can see it.

becausein vb works

you are kidding, I hope