Search code examples
actionscript-3inheritancereferencemovieclip

Actionscript 3: Referencing data in groupings of movieclips


I'm a very new programmer. I'm making a character calculator for a friend of mine's game, but mostly for practice for myself.

I'm programming in Actionscript and have been trying to reference Data in Lists, which has been working fine, except when my lists are grouped together with anything else as one symbol(MovieClip).

I have looked around the internet and tried getChild() (though I am not positive symbols in other symbols mean they are children of them), as well as putting MovieClip(parent).ListName.Data to try and reference it. I have also simply tried putting ListParent.ListName.Data to reference it, but I'm afraid I'm at a loss.

I'm sure the answer is very obvious but Google, as it seemed, did not pinpoint my issue. Here is the code -- my list's dataProvider is pretty much just 1, 2, 3, 4, 5 for my data points, so here I'm trying to reference list selection 2:

earthponyRacials.earthponyList1.addEventListener(Event.CHANGE, testText);

function testText(event:Event) {
    if(earthponyRacials.earthponyList1.data == 2){
        trace("Function working?");
    }
}

This is my reference error:

ReferenceError: Error #1069: Property data not found on fl.controls.List and there is no default value.
at CharacterCalculator_fla::MainTimeline/testText()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::SelectableList/handleCellRendererClick()

I'm sorry if this is a really obvious question.


Solution

  • You have to access the lists data using:

    YourList.dataProvider.getItemAt( ItemsIndex ).data;
    

    You can also get its label by replacing .data with .label The items index is the same as accessing an array so item 2 is index 1 item 1 is index 0

    Hope this helps!