View Full Version : how to find the parent or container of an object
Blade[UG]
12-01-2010, 12:21 AM
I'm receiving CLIK events for a dropdown, but the Target that I receive in the unrealscript function is the gfxobject for the menu item selected .. I need to know in which menu it was selected.. how do I retrieve the parent container?
ffejnosliw
12-01-2010, 12:38 AM
In ActionScript, I believe DisplayObjects have a parent property that holds the container of the DisplayObject. If you can access that, it might give you what you need.
Matt Doyle
12-01-2010, 10:16 AM
In UnrealScript use:
MyClikWidgetName.GetString("_parent");
This returns the instance name of the parent. in this format: _level0.parent
Blade[UG]
12-01-2010, 11:10 AM
Edit:
I thought it was working, but all I checked was that it was returning something that looked useful..
GetString("_parent") returns "_level0" for everything .. GetObject("_parent") returns .. some kind of GFxObject, but it's definitely not the CLIKWidget drop-down that contains the object in question.
I was hoping to have one callback for several dropdown boxes.. but I guess I'll go back to doing it in seperate callbacks.
Matt Doyle
12-01-2010, 11:58 AM
Strange. It works on my end. Oct. UDK. I have a CLIK label inside a movie clip, and it returns the instance name of the movie clip as the parent. So this doesn't work?
function OnChange(GFxClikWidget.EventData ev)
{
`log("Parent of target: "@ev.target.GetString("_parent"));
}
Blade[UG]
12-01-2010, 12:22 PM
well, what we have is:
var GFxClikWidget DropDownWidget;
...
event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget) {
....
DropDownWidget.AddEventListener('CLIK_change', GearChange);
....
}
function GearChange(GFxClikWidget.EventData ev) {
`Entry(ev.target.GetString("_parent") @ ev.target.GetObject("_parent"));
}
gives me: _level0 GFxObject_xxx where xxx appears to be unrelated to the ev.target .. although it may be, but i'm not sure what variables would be available on the Scaleform side to query with Get* functions .. is there a reference for that sort of thing? I'm sort of muddling through learning this stuff with this, I don't know AS at all..
Matt Doyle
12-01-2010, 12:43 PM
Well, if your drop down lives on the _root timeline, and is not nested inside a movie clip, it will indeed return _level0 as the parent.
Your CLIK_change event is fired off by the drop down menu, and not the individual components of that menu, which I think are essentially buttons.
Matt Doyle
12-01-2010, 01:10 PM
Give me some time and I'll get back to you on this.
Matt Doyle
12-01-2010, 01:59 PM
Ok, I think I just realized what you're doing. As I said, you seem to be assuming the CLIK_change event is being fired by the list item renderer (the various rows of your drop down), when in actuality it is being fired by the drop down itself.
So, All you need to do is get get the _name property of ev.target to get the instance name of your drop down. Each item row is a descendant of the drop down. I believe it goes: ListItemRenderer -> container movie clip -> ScrollingList -> DropDownMenu.
function GearChange(GFxClikWidget.EventData ev)
{
`Entry(ev.target.GetString("_name")); // returns the instance name of the drop down
}
Blade[UG]
12-01-2010, 05:05 PM
aha. that at least returns me something i can use to identify the right thing. was hoping to use objects, i hate doing string compares when I don't have to, but at least that will get me to the right place. You're totally right, I was assuming since I was getting something entirely different back, that I was getting the element itself.
My question now, is, what am I getting? When I select something in "GearDropDown", I get a GFxObject as the ev.target .. but it is not the GFxClikWidget, it's just a GFxObject. Some sort of odd thing about going between the two languages?
Matt Doyle
12-01-2010, 05:39 PM
Ok, so GetObject works like GetString or GetFloat. GetString is used to get a string value with the given variable name. GetObject is used to get an object. So, in a list, you would have a dataprovider, which is just an array - a simple object. You could use mylist.GetObject("dataProvider") to get that object.
Here's an example usage:
var GFxObject MC, TF;
TF = MC.GetObject("message").GetObject("textField");
This assumes MC is defind elsewhere.
So, we're using GetObject to get a text field (with the instance name "textField") which lives inside the "message" movie clip in Flash, and assigning that text field to TF.
We can then use the TF GFxObject with something like this:
TF.SetBool("html", true);
TF.SetString("htmlText", "<strong>Something cool!</strong>");
Blade[UG]
12-02-2010, 12:18 AM
ok, so when I look at ev.target, that is a GFxObject. But it is NOT equivalent to my "GearDropDown". But when I get ev.target.GetString("name"), it's name is that of the GearDropDown. So, it appears that it IS my GearDropDown, but GearDropDown != ev.Target, and GFxClikWidget(ev.Target) == None. Does that make sense as tow hy it's confusing me?
Matt Doyle
12-03-2010, 10:20 AM
I'm fairly certain ev.target (in this case) IS the dropdown. That's why you can do ev.target.GetString("name") and return its instance name.
Blade[UG]
12-04-2010, 12:38 AM
right, it is, I'm just trying to wrap my head around why it doesn't == the same thing that I got in WidgetInitialize.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.