ИГРОДЕЛ
Войдите на сайт или зарегистрируйтесь!!!

Flex: Как получить стек вызовов?

Перейти вниз

Flex: Как получить стек вызовов?

Сообщение автор Admin в Вс Фев 21, 2010 9:24 pm

Недавно я имел дело с клиентом, который пытался отладить компоненты Flex. В некоторых случаях по непонятным причинам вызывался метод компонентов updateDisplayList().
При написании и отлаживании компонентов Flex иногда полезно знать, кто именно вызывает данный метод, чтобы понять, в чем дело. Здесь подойдет профайлер, но, к сожалению, протокола для версии Flex 2.0 (или 2.0.1) не существует. Мы беседовали с разработчиком Flex Алексом Хоруи (его блог можно увидеть здесь ), и вот какую стратегию он посоветовал:

- Поделить на классы компоненты, которые Вас интересуют (или если Вы пишете свои собственные компоненты, просто добавьте к ним нижеизложенное).

- Заменить методом invalidateDislayList() (или тем методом, который Вам нужен).

- Создать новый объект-«ошибку».

- Вывести объект-«ошибку» метода getStackTrace().


Эти действия помогут установить иерархию запросов, которые являются причиной вызова invalidateDisplayList. (И именно сигнал метода invalidateDisplayList будет указывать на вызов updateDisplayList())


Все это звучало весьма логично, и я подготовил следующую модель. Я решил использовать модель из документации Flex, которая расширяет функциональность VBox до “BottomUpVBox”, которая уже способна классифицировать объекты, располагая их сверху вниз, что совершенно противоположно стандартной последовательности VBox.

BottomUpVBox.as

package{ import mx.containers.VBox; import mx.core.EdgeMetrics; import mx.core.UIComponent; public class BottomUpVBox extends VBox { [Bindable] public var callStack:String; public function BottomUpVBox() { super(); } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); // Get information about the container border area. // The usable area of the container for its children is the // container size, minus any border areas. var vm:EdgeMetrics = viewMetricsAndPadding; // Get the setting for the vertical gap between children. var gap:Number = getStyle("verticalGap"); // Determine the y coordinate of the bottom of the usable area // of the VBox. var yOfComp:Number = height-vm.bottom; // Temp variable for a container child. var obj:UIComponent; for (var i:int = 0; i < numChildren; i++) { // Get the first container child. obj = UIComponent(getChildAt(i)); // Determine the y coordinate of the child. yOfComp = yOfComp - obj.height; // Set the x and y coordinate of the child. // Note that you do not change the x coordinate. obj.move(obj.x, yOfComp); // Save the y coordinate of the child, // plus the vertical gap between children. // This is used to calculate the coordinate // of the next child. yOfComp = yOfComp - gap; } } override public function invalidateDisplayList():void{ super.invalidateDisplayList(); var e:Error = new Error callStack += "\n\n *** Call to invalidateDisplayList() *** \n"; callStack += e.getStackTrace(); trace(e.getStackTrace()); } }}
Программный код для BottomUpVBox компонента по сути тот же, что и для данных документов, кроме двух деталей:

- Я выкладываю информацию в публичный доступ, присваиваемой переменной и callStack.

- Я заменяю метод invalidateDisplayList(), как сказано в инструкции, создаю новый объект-«ошибку» и получаю getStackTrace().


Здесь находится приложение, в котором я, используя BottomUpVBoх, получаю callStack (снова – практически полностью из документации Flex).

<?xml version="1.0"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:MyComp="*" > <MyComp:BottomUpVBox id="BUVB"> <mx:Label text="Label 1"/> <mx:Button label="Button 1"/> <mx:Label text="Label 2"/> <mx:Button label="Button 2"/> <mx:Label text="Label 3"/> <mx:Button label="Button 3"/> <mx:Label text="Label 4"/> <mx:Button label="Button 4"/> </MyComp:BottomUpVBox> <mx:TextArea width="400" height="600" text="{BUVB.callStack}"/> <mx:Button label="click to invalidateDisplayList() of BottomUpVBox" click="BUVB.invalidateDisplayList()"/> </mx:Application>

Просто запустите приложение нижеприведенную трассировку callStack, которая очень информативна:

null *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/set enabled() at mx.core::Container/set enabled() at mx.core::UIComponent$iinit() at mx.core::Container$iinit() at mx.containers::Box$iinit() at mx.containers::VBox$iinit() at BottomUpVBox$iinit() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/styleChanged() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/styleChanged() at mx.core::Container/styleChanged() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/mx.core:UIComponent::childrenCreated() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.core::Container/addChildAt() at mx.core::Container/addChild() at mx.core::Container/createComponentFromDescriptor() at mx.core::Container/createComponentsFromDescriptors() at mx.core::Container/mx.core:Container::createChildren() at mx.core::UIComponent/initialize() at mx.core::Container/initialize() at mx.core::Application/initialize() at main/initialize() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded() at mx.managers::SystemManager/::initializeTopLevelWindow() at mx.managers::SystemManager/::docFrameHandler() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::Container/styleChanged() at mx.core::UIComponent/notifyStyleChangeInChildren() at mx.core::Container/mx.core:Container::commitProperties() at mx.core::UIComponent/validateProperties() at mx.managers::LayoutManager/::validateProperties() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/styleChanged() at mx.core::Container/styleChanged() at mx.core::UIComponent/notifyStyleChangeInChildren() at mx.core::Container/mx.core:Container::commitProperties() at mx.core::UIComponent/validateProperties() at mx.managers::LayoutManager/::validateProperties() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/validateSize() at mx.core::Container/validateSize() at mx.managers::LayoutManager/::validateSize() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() *** Call to invalidateDisplayList() *** Error at BottomUpVBox/invalidateDisplayList() at mx.core::UIComponent/setActualSize() at mx.containers.utilityClasses::Flex$/flexChildHeightsProportionally() at mx.containers.utilityClasses::BoxLayout/updateDisplayList() at mx.containers.utilityClasses::ApplicationLayout/updateDisplayList() at mx.core::LayoutContainer/mx.core:LayoutContainer::updateDisplayList() at mx.core::Application/mx.core:Application::updateDisplayList() at mx.core::UIComponent/validateDisplayList() at mx.core::Container/validateDisplayList() at mx.managers::LayoutManager/::validateDisplayList() at mx.managers::LayoutManager/::doPhasedInstantiation() at Function/http://adobe.com/AS3/2006/builtin::apply() at mx.core::UIComponent/::callLaterDispatcher2() at mx.core::UIComponent/::callLaterDispatcher() Надеюсь, кому-то из вас это будет полезно.

Полную версию FlexBuilder 2.0.1 Project Archive (.zip) можно найти здесь .
avatar
Admin
Admin

Сообщения : 92
Очки : 280
Репутация : 36
Дата регистрации : 2010-02-20

Посмотреть профиль http://game-dll.mirbb.net

Вернуться к началу Перейти вниз

Вернуться к началу


 
Права доступа к этому форуму:
Вы не можете отвечать на сообщения