Flex :: Disptaching Custom Event From Custom Component?
Feb 16, 2012
This is similar to the question asked here. I am dispatching custom event "ShopEvent" but i am getting error "Type Coercion failed: cannot convert flash.events::Event@81ecb79 to com.events.ShopEvent"Note: Error is thrown from the parent custom component (3rd code snippet), I have added more details thereThis is my custom event. See the first constant, I copy pasted the event name in custom components.
This is NOT duplicate of my earlier post (its is slightly different)But this is similar issue with similar error but its not the same error The error I am getting now is below while dispatching the custom event from my custom component
TypeError: Error #1034: Type Coercion failed: cannot convert events::MapEvent@a74ab51 to flash.events.MouseEvent. dispatchEvent(new MapEvent(MapEvent.CLICKED_ON_MAP));
Note: The error in my earlier post is giving below error message
Type Coercion failed: cannot convert flash.events::Event@81ecb79 to com.events.ShopEvent
The difference here are two things, the earlier error is while converting flash event to custom event and now this one is while converting custom event to flash event and secondly, I have no clue why it is trying to convert to the mouseevent where I am just dispatching my custom event with proper listeners.
I have a custom Flex 4.5 component (to be used in a List) -
Game.mxml (represents a clickable playing table in a card game): <?xml version="1.0" encoding="utf-8"?> <s:ItemRenderer [code].......
But I never see the "game clicked: " trace. Does anybody please know why? I'm probably missing something minor, because I can see the "Clicked: 8946" trace.
I'm just getting started with custom events in a custom component. And I don't quite have the hang of it, yet. I've got a component with a button in it. When it's clicked, I want to call a function in the main app.
I am trying to understand event propagation in Flex framework and have a following doubt on it:
Scenario: I have a built-in component DropDownList on change of which I want to create a custom event refreshPreview and want to propagate it to a custom component PictureComponent.
In the custom component's mxml, I have added the Metadata directive as follows to register a refreshPreview event with the compiler
Layout Details: In my main mxml application I have laid out DropDownList and the custom component such that both are siblings (i.e. have a common indirect parent) e.g.
I am seeing that the refreshPreview event is not getting propagated to the custom component.
I doubt this is because the built-in component is a sibling of the target (where the event got generated) and not a parent. how to make refreshPreview event propagate to custom component?
I made a movieclip in flash that dispatches a custom event: MyEvent.THE_TYPE = "the_type"in flex I have: <local:my_flash_mc the_type="do_something()"however, this is not working.in flash, my event bubbles is set to true. everything works fine in flash.in flex I am NOT using:
I have the following situation:I have an event handler, that displays small messages in my application's statusbar.These messages get passes through by dispatching events from custom components.A simple message could be like "HTTP Error" or so.Now, the main event listener, in the main application file, listens to the event dispatched by any custom component,but seems to refuse listening to events dispatched by custom AS classes.Here is my code for the custom event:
I have a custom component made up of a selectable control (radio button)and a text input. I want to perform some logic in response to the change events from both of those controls, but after that I want anything that is registered on the composite component's change handler to have a change to handle the events as well. The problem is, when I re-dispatch the events the event target has changed to my custom component, losing the originating event's target.
In the event handler that receives change events from this component, I see that event.target is an instance of SpecifyRadioButton, not the TextInput or RadioButton, as I'd expect. How should I propagate the event to get what I want here?
Getting event [Event type="change" bubbles=false cancelable=false eventPhase=2] from question0.tabSurvey.questionForm.questionContainer.Single94.VBox95.SpecifyRadioButton111
In short: I need an event listener in a custom component so all its instances (without editing them) react at the same time, fired by a dispatched event in its parent container. In detail: I have a custom component with Tab navigator. (The tabs are intended to show different preferences for different Languages.) I have a button bar with buttons for all the languages. There are a lot of instances of the custom component.
I want to click in a button of the languages bar and get ALL the instances switched to the same tab (the custom component contains the logic to change the tab). I can do it by adding the event listener for EACH INSTANCE of the custom component, so it calls an internal function that changes the tab. But it seems to be very coupled, isn't it? I wonder if it can be done in the master CLASS of the component, so it listen for events in its parent container, whichever it is. In my mind this code shoud work, but it doesn't (obviously ill'use a custom event to pass the new language value): this.parent.addEventListener("lang_change", this.change_tab); This way I can just drop an instance of the component, and see it working for itself.
The spark panel component for example can be written like this
<Panel title="Skinny"> <child components ... /> <controlBarGroup> <child control bar components ... /> </controlBarGroup>
[Code]...
The motivation here is that I can now create a couple different skin files to change the look and layout of those subgroups. Reading source of the spark panel, there are some calls within the mx_internal namespace such as getMXMLContent() which is a method of the spark group component, but which I have no access to.
Does the description above make sense? How can I create custom 'contentGroups' in my custom Flex4 component that can use nested mxml child components? Should I approach this a different way?
I have a repeater component with custom event. My repeater components fires custom event holding data. My need is to dispatch event so other repeater components can access data from dispatching component.
I have a Custom Component that has a couple of Canvas with some background colors assigned to them. Now i have hard coded the colors, i want to move them to an external css file. So i would like to have the css declaration like this :
[Code]...
My question is if i can define custom style names like dividerRightColor and if so, how can i use that value inside my MXML Component? I have seen examples of using them inside Pure AS components.
I have created custom TreeItemRenderer in which i am trying to draw colored Hbox bar at each node except root. Intially when i click on root node it opens first child node with bar but when i open leaf node it does not showing bar and removing existing bard from other few child nodes. Its calling itemrenderer on mouseonver eventhough i have disabled.Attaching Code here
i am a bit embarassed to ask this, but i do this so much i have to ask. Occasionally, i need to pass/handle custom events on the fly. Rather than creating a whole custom event class, i will just do something like
Code: myObject.dispatchEvent(new Event('thisCustomEvent')); //and then handle it later
I'm building a top view 2D map, that it's objects are stored on the server.The kind of objects are 10 and might be a photo, label, button, lists, mix of them or labels with tooltips.The component must request the "areas" that are missing on screen.An area is 1000x1000 px and is cached in flex.To move in the map, will be like in google maps (drag-and-drop).I should be able to have another list and move objects from one to another using drag-an-drop on objects. Ex.: I grab an objects from a list and I move it on this map, I release the mouse button and the item is placed there.Now the problem is: I build a custom component for this trying to emulate the item renderer for performance and recyclage, implement drag-and-drop on objects and request the areas that are missing?
or
I extend the List component from spark and I add some features as multiple kind of itemrenderers and use recycle on them. Of course it must be able to request the missing areas on the screen and cache it's data.Maybe create a custom layout is needed too.What I need is something that must be really fluid, so the lighter this component is, the better.
UPDATE: *There will be not any object over another.
*I will not use hitTest on bitmaps because all bitmaps are wrapped in another component,as they,for now are itemrenderers.
Anyway I already begin to do this using a class that extends the SkinnableDataContainer and a custom layout. As the layout is not like a grid, is sparse, random items at diferent points(x, y).How to get the localX and localY, relative to item renderer and not to the Spark List, from a DragEvent in Flex 4?
I hava a custom component and it contains a child icon. If I add a mouse-click event listener to both component(click-listener1) and icon(click-listener2), the event dispatched sequence is click-listener2, then click-listener1. I can understand it. But if I add a custom event to component (listener1), and mouse-click event to icon(listener2), when icon is clicked, the component will dispatch the custom event. In my test, the event dispatched sequence is listener1, then listener2. It doesn't match with event-bubbles rule.
In my opinion The custom event is dispatched in listener2, which triggers listener1. Why event flow sequence is not listener2, listener1?
In component.
icon.addEventListener(MouseEvent.CLICK, iconClickHandler); private function iconClickHandler(event:MouseEvent):void {
I am having trouble using a custom event in flex. I need to dispatch an event from inside two nested components and receive it in the main application file. The basic set up is a main application file importing a custom "gallery" component.
is there any way to create a custom css value for a component and have it available to the skin class that component is using? for example, if i define this in a css file:
[Code]....
is there a way to make myCustomValue available in the PanelSkin ?
I'm making a UI for a component in Flash. I wanted to use Flex and have had no luck getting the onUpdate exernalInterface call to fire properly. I'm referencing the functionality described here: [URL]. First off, I can't embed the SWF in the FLA. It just won't start the Flex SWF. Even using the external swf, it seems that the onUpdate function is either called too early or not at all. Here's what I've tried:
Tying the externalInterfce declaration to the initialize, preinitialize, applicationComplete, and creationComplete events. Sub-classing my application and putting the externalInterface in the constructor. Neither of these options work. When I create a basic AS3 project in Eclipse and put the externalInferface in the constructor, it works as expected.
printableInvoice.addEventListener(batchGenerated, printableInvoice_batchGeneratedHandler);Results in this error: 1120: Access of undefined property batchGenerated. I have tried it as FlexEvent.batchGenerated and FlashEvent.batchGenerated.
The MetaData and function that dispatches the even in the component printableInvoice is all right. It I instantiate printableInvoice as an mxml component instead of via action-script it well let put a tag into the mxml line: batchGenerated="someFunction()
Our software team has been developing flash applications using AS3 (via the FlashDevelop IDE and the free Flex SDK). Recently, some members of the team started exploring FlexBuilder and Flex (wow... why did we wait so long?). The problem is that some folks continue to develop using pure Action Script 3 (FlashDevelop) while others are creating custom components in FlexBuilder. How do the AS3 developers use the Flex Custom components built in FlexBuilder in their AS3 Applications?
I used a FlexBuilder Library Project to create a custom component library (swc). The custom component is a control bar with text fields and buttons, etc.The vast majority of our team's code is done in pure AS3 I've successfully included my new SWC in the lib and build path in our AS3 project.I've also successfully instatiated an instance of my custom component, but for some reason, it will not display. I know it exists, because 1) the compiler had no complaints, and 2) I can trace property values of the custom component and get valid output from the trace statement.
trainer.games.board.MatchThree { import flash.display.Sprite; public class Test extends Sprite{
I am creating a custom component in Flex with extends the BorderContainer class, and I would like to be able to place additional content within the tagset when I use it in my main application, like this:
<components:CustomComponent title="Hello"> <s:Label text="If you have one enter it below:"/> <mx:Spacer height="15" />
[Code]....
This works just fine, except that my component definition had some additional things inside of it, such as a <s:Label/> and styling, which is replaced by the content within the tagset above when I go to use it.
If I do not put anything within the tagset, the content that was originally in the component is not replaced.
Is there a way that I can simply append additional content inside of the component when I go to use it, instead of it being replaced each time?
I created separate own canvas component for Home page, Contact page, Rules page etc.In my main application it has link button like Home,Contact,Rules in application controller(child state) . [code]...
I want my custom button to look like the button sample below. More specifically, I want the width of the button to be determined by the width of the largest word in the label (i.e. width of "Elongated" in my example). The label must wrap, not truncate. And I want only one pixel between the top edge of the icon and my button's top edge. I have tried lots of things but to no avail so far. I have reduced the horizontalGap and verticalGap to zero and padding to zero. But still nothing.