Copy link to clipboard
Copied
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
but still displaying it as object
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
Copy link to clipboard
Copied
but still displaying it as object
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
thank you , but only 1 question
why we cant do that
itemname11.text = listbox1.getItemAt({label:listbox1.selectedindex)
it makes more sense to me , because we gonna get item from the label and then
we need the index number
but i cant see this property(label) in the list methods , it is in data provider as i see , because of
that iam wondring from .label , i know not all the method should be in the properties
but still i cant understand the way , i mean .label..
can you explain more please
sorry again and thank you a lot for your help
Copy link to clipboard
Copied
it makes more sense to me
Because you don`t see the "Bigger Picture".
The index-number of every entry in your list is Unique,
whereas its no problem to have multiple doubles of data or label.
It makes more sense to identify things on there unique properties.
So while the View of your application seems to point to the string that you select with your mouse.
Internally it points to the index of the dataProvider
Copy link to clipboard
Copied
i get it :d
thank you alot moccamaximum
Copy link to clipboard
Copied
lol i guess iam confusing again
here
itemname11.text = listbox1.getItemAt(listbox1.selectedindex)
Copy link to clipboard
Copied
listbox1.getItemAt(listbox1.selectedindex).label
Copy link to clipboard
Copied
lol no not this , ididn,t complete it
here
lol i guess iam confusing again
here
itemname11.text = listbox1.getItemAt(listbox1.selectedindex)
if i do this without label i will get the numbers , right because it is array as i guess
but i tried to understand it more
now i want to see the label 1 or 2 and i wrote juice init
i was trying to do this trace(listbox1.dataProvider.index[1] )
but i get error
and i realy dont know why
it says index error and some stuff
Copy link to clipboard
Copied
sorry i didn.t explain it good
i revise the vb
here
http://www.youtube.com/watch?v=4kUoHNEpCmQ
in vb i can do this list.selected(itemnumber) but how can i do like this
in as3
sorry because my questions are too much
thank you
Copy link to clipboard
Copied
Maybe this will help you:
1.Drag a List control from the components panel on stage.
2.Name it "_List" in the property panel
3.Drag a TextArea component on stage
4.Name it "_TextArea"
5.Insert the following code on the first frame of your timeline
import fl.data.DataProvider;
var list_dp:DataProvider = new DataProvider();
for (var i:int = 0;i<5;i++){
list_dp.addItem( { label: "Label"+i, data:i });
var _text:String = "Label"+i+"\n";
_TextArea.text += _text;
}
_List.dataProvider = list_dp;
_TextArea.height = _List.height;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now