Actionscript 3: Referencing data in groupings of movieclips - actionscript-3

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.

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!

Related

StencilJs value does not exist on type 'Element'

I want to set the value of an ion-input field when the page is loaded.
I'm trying to get the element from the shadowDom using the shadowRoot querySelector.
It is a stencil project with ionic. The component uses the shadowDOM.
When I try to get the value my IDE says:
The nameEl:
const nameEl = this.el.shadowRoot.querySelector('#name');
The value will be set correctly, but I was wondering how I could fix this error message.
EDIT:
Answer as suggested by Ash is correct. And like Ash mentioned there are two ways of implementing this solution. But I was wondering if there is any difference between the solutions?
const nameEl = this.el.shadowRoot.querySelector('#name') as HTMLInputElement;
or
const nameEl: HTMLInputElement = this.el.shadowRoot.querySelector('#name');
EDIT:
The solution of course also work as one-liners as in Ash his example.
(this.el.shadowRoot.querySelector('#name') as HTMLInputElement).value
And in my case the input is a ionic input:
(this.el.shadowRoot.querySelector('#name') as HTMLIonInputElement).value
Setting the value works as you said but the reason for the error is as the message says Property 'value' does not exist on type 'Element'. To phrase it differently to help you understand, the message is saying:
You have something of type Element
The value property does not exist on the type definition for that something
Therefore you need to either correct the code to get the right type of element or in your case tell the code what to expect.
(<HTMLInputElement>nameEl).value
// OR
(nameEl as HTMLElement).value
The above snippets were taken from the related questions below and updated to match your variable names.
I answered here because you mentioned Stencil but is not related to the issues, however this question is a duplicate and answers for similar questions can be found at Property 'value' does not exist on type 'EventTarget' and Property 'value' does not exist on type EventTarget in TypeScript

XrController.hitTest not returning any ESTIMATED_SURFACE or DETECTED_SURFACE results

I'm calling
XrController.hitTest(X, Y, ['FEATURE_POINT','ESTIMATED_SURFACE', 'DETECTED_SURFACE'])
But all the results I'm getting are of type 'FEATURE_POINT' only.
If I leave out 'FEATURE_POINT' from the included types
XrController.hitTest(X, Y, ['ESTIMATED_SURFACE', 'DETECTED_SURFACE'])
I'm not getting any results at all.
Are 'ESTIMATED_SURFACE', 'DETECTED_SURFACE' not implemented yet, or do I need to do something specific in order to get them
Thanks
The ESTIMATED_SURFACE and DETECTED_SURFACE options are in the spec but aren't currently a features of 8th Wall Web. Only FEATURE_POINT is currently implemented.
Currently only 'FEATURE_POINT' is supported in 8th Wall. You can reference this document: https://www.8thwall.com/docs/web/#xr8xrcontrollerhittest

Selecting some kind of closest child with jQuery seems not to work

I try to implement a nested tab module the following way.
By clicking on a .tabs__menu item I want to get the next .tabs__contents to display the correct entry.
I've prepared a codepen with markup and leave out all unimportant code so don't be irritated that it's not working. I don't understand why the variable debug2 is 0 and debug3 is 1. I expect debug2 to be 1 as well since I expect the following expression should find the element. Can anyone help me with this?:
.find(".tabs__contents").not(".tabs__contents .tabs__contents");
https://codepen.io/anon/pen/JNLWQp
Thanks in advance and best wishes,
duc
ok I have an assumption why it's not working. It seems that the .not method doesn't starts to search relatively from the given collection but globally. With this statement
.not(".tabs__contents .tabs__contents")
debug2 finds itself and exclude it from the collection thats why the length is 0.

AngularJS - Conditionally display key and value if they exist

This may be a little confusing to describe.
Basically, I am parsing multiple external JSON feeds that display in different views depending on the 'active tab' displayed. They both share the same partial template, so they both look exactly the same, just different content.
The problem that I am facing now is, that in some feeds, some keys are placed in an array and others are not.
For example, the feeds parses this kind of data:
JSON Feed 1 - One 'attributes' inside of 'link'
"link":{
"attributes":{
"href":"www.link1.com"
}
}
JSON Feed 2 - Two 'attributes' inside of 'link'
"link":[
{
"attributes":{
"href":"www.link1.com"
}
},
{
"attributes":{
"href":"www.link2.com"
}
}
]
The only way I am able to get the value "www.link1.com" is via:
For Feed 1:
link1
And for Feed 2:
link1
I am trying to figure out what would be the best way to do:
1) If link[0] exists - display it, else if [link] exists, display that instead.
2) Or if targeting the activeTab would be safer? For instance, if activeTab = view2 or view4, use [link][0], else if activeTab = view1 or view3 use [link], else if I do not want it to be displayed, do not display anything.
Also a relatable question, if I am on view2 can I only display [link][0] on that view?
Any feedback would be appreciated. Thanks!
In your model controller, you can reconstruct the JSON objects to make them similar. The value of link in both feeds should be an array.
Then in your template you can simply use ngRepeat to get the items from inside the array.
Okay - so I found a solution to one of the questions above: "How to only display [link][0] in a specific view"
Pro: It's a simple code that depends on the activeTab / view that is being displayed.
Con(?): Since I am really a newbie to AngularJS - not sure if this is the best solution.
Basically:
Depending on the ng-view that is currently displayed, than a specific JSON object will be displayed, such as:
<a ng-show="activeTab == 'view1' || activeTab == 'view3'" ng-href="{{item['link'][0]['attributes']['href']}}">
<h6>Link1 from Feed2</h6>
</a>
Although the primary question is still unresolved: How to swap/switch JSON objects (key,values) if one exists, and not the other. I am still definitely trying to find a solution, although any help is still appreciated.
Please let me know what you think, or how I can improve the solution to the problem!
Thanks!
Roc.

How to represent an empty Array in Action Script 3.0

i'm trying to make a question game with 30 question divided into 3 dificulties, so i'm using arrays to have my questions randomized but not repetitive.
I made the code use the first parameter of the array (array[0]) then remove it from the array.
So, my array will have no more elements after a time. But, when my array have only 1 element, i cant play this element, and i need to use the representation of the empty array to get it to play.
I'm new on AS3, so this may seem very confusing. Here is the code I used.
btn_1.addEventListener(MouseEvent.CLICK,retor);
function retor(e:MouseEvent):void{
trace(vaitemp);
gotoAndStop(1,vaitemp[0]);
vaitemp.splice(0,1);
if(vaitemp.length==0){
trace ("acabou")
gotoAndStop(1,vai2temp[0]);
vai2temp.splice(0,1);
trace(vai2temp)
}
}
I need to represent the "vaitemp" Array as an empty array at the "if"function, so it will play the last element and THEN go to the next array (the "medium dificulty group").
Well, the question is preety messy, i hope any of you can understand what I want.
The literal for an empty array is just []. As in var emptyArray:Array = [];