Actual target for MouseEvent.CLICK - spark skins

Hello,
I have a question about Event Listeners and targeting events.
In my AIR app for mobile I need to click / tap on a number of s:Image objects.
At first I added to each of them an Event Listener linked to an Event Handler. Then, trying to optimize my code, I moved the Event Listener to the container object as suggested in various optimization resources I found online.
The problem was that the event.target property was not the clicked image, but a s:Group. I eventually figured out that the s:Group was part of the skin of the s:Image, and I fixed the problem by using the target.owner property, but this behavior really created a lot of confusion. I couldn’t find anything about it on the Adobe development resources, as they just insist on (and explain quite well) the difference between the target and currentTarget properties.
Below you can find a simple representation of my workaround, but I was wondering if:
1) This was actually caused by some mistake I made, and if it could be more easily avoided;
2) There is a better or more efficient workaround than the one I came up with;
3) The topic is discussed somewhere in the documentation.
Thanks a lot!
import spark.components.Image;
private var image1:Image;
private function initComponent():void
     image1 = new Image();
     image1.source = "assets/aaa.png";
     image1.id = "thisIsTheImage";
     addElement(image1);
     addEventListener(MouseEvent.CLICK, clickHandler);          // 1
//   image1.addEventListener(MouseEvent.CLICK, clickHandler);     // 2 - the old one
private function clickHandler(event:MouseEvent):void
     trace("event.currentTarget \t\t\t" +              event.currentTarget);
     trace("event.target \t\t\t\t" +                   event.target);
     trace("event.target.owner.owner \t\t" +           event.target.owner.owner);
     trace("image1.imageDisplay.displayObject \t" +    image1.imageDisplay.displayObject);
     if(event.target.owner.owner is Image){
          // do something
console:
event.currentTarget                     TestApp0.ViewNavigatorApplicationSkin2.navigator.ViewNavigatorSkin4.contentGroup.TestView33
event.target                            TestApp0.ViewNavigatorApplicationSkin2.navigator.ViewNavigatorSkin4.contentGroup.TestView33.SkinnableContainerSkin35.contentGroup.thisIsTheImage.ImageSkin43.Group44
event.target.owner.owner                TestApp0.ViewNavigatorApplicationSkin2.navigator.ViewNavigatorSkin4.contentGroup.TestView33.SkinnableContainerSkin35.contentGroup.thisIsTheImage
image1.imageDisplay.displayObject       TestApp0.ViewNavigatorApplicationSkin2.navigator.ViewNavigatorSkin4.contentGroup.TestView33.SkinnableContainerSkin35.contentGroup.thisIsTheImage.ImageSkin43.Group44

Hey,
thanks a lot!
What about using SpriteVisualElement?
By looking at ther inheritance chains it should be lighter than Image but heavier than BitmapImage:
Image SkinnableComponent UIComponent FlexSprite Sprite DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object
SpriteVisualElement FlexSprite Sprite DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object
BitmapImage GraphicElement EventDispatcher Object
I'd like to use it over BitmapImage beacause it inherits from InteractiveObject and is therefore clickable.
Would this be a good idea?

Similar Messages

  • [svn:fx-trunk] 10006: Initial checkin of the "More styles for Spark skins" feature.

    Revision: 10006
    Author:   [email protected]
    Date:     2009-09-03 15:04:47 -0700 (Thu, 03 Sep 2009)
    Log Message:
    Initial checkin of the "More styles for Spark skins" feature. Details here:
    http://opensource.adobe.com/wiki/display/flexsdk/MoreStylesforSparkSkins
    There are some known issues:
    Panel bottom corners not rounded correctly when the panel has a control bar
    cornerRadius on Tab and DateChooser non functional
    cornerRadius values > 4 have drawing artifacts in the "down" state of Button and button-like components
    TextInput/TextArea incorrectly list lineBreak and verticalAlign as valid styles
    This checkin also includes a couple minor unrelated bug fixes:
    Remove MiniDebugTarget. This is a logging target that used MiniDebug, which hasn't worked since Flex 1.5
    Fix RTEs when setting focusSkin to null
    Optimization: don't measure skins if the host component has explicit sizes
    QE notes: Yes, many baseline images will need to be regenerated
    Doc notes: New ASDoc comments should be scrubbed
    Bugs: SDK-22931, SDK-22798, SDK-22217, SDK-19358
    Reviewer: Jason
    Tests run: checkintests, cyclone
    Is noteworthy for integration: Yes
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22931
        http://bugs.adobe.com/jira/browse/SDK-22798
        http://bugs.adobe.com/jira/browse/SDK-22217
        http://bugs.adobe.com/jira/browse/SDK-19358
    Modified Paths:
        flex/sdk/trunk/frameworks/halo-manifest.xml
        flex/sdk/trunk/frameworks/mxml-manifest.xml
        flex/sdk/trunk/frameworks/projects/airframework/defaults.css
        flex/sdk/trunk/frameworks/projects/airframework/src/spark/components/Window.as
        flex/sdk/trunk/frameworks/projects/airframework/src/spark/components/WindowedApplication. as
        flex/sdk/trunk/frameworks/projects/airframework/src/spark/skins/spark/SparkChromeWindowed ApplicationSkin.mxml
        flex/sdk/trunk/frameworks/projects/airframework/src/spark/skins/spark/WindowedApplication Skin.mxml
        flex/sdk/trunk/frameworks/projects/framework/defaults.css
        flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/ComboBase.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/DateChooser.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/NumericStepper.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/TextInput.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/core/Container.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/core/IDeferredContentOwner.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/core/INavigatorContent.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/core/ScrollControlBase.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UIComponent.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/styles/metadata/BorderStyles.as
        flex/sdk/trunk/frameworks/projects/spark/defaults.css
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/Application.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/DropDownList.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/List.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/NumericStepper.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/Panel.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/Scroller.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/SkinnableContainer.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/Spinner.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/ButtonBase.a s
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/GroupBase.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/Skin.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/SkinnableCom ponent.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/SkinnableTex tBase.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/Slider.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/RectangularDropShadow.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/SparkSkin.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/ApplicationSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/ButtonBarFirstButtonSkin.m xml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/ButtonBarLastButtonSkin.mx ml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/ButtonSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/DefaultButtonSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/DropDownListButtonSkin.mxm l
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/DropDownListSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/FocusSkin.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/ListSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/NumericStepperTextInputSki n.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/PanelSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/SpinnerDecrementButtonSkin .mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/SpinnerIncrementButtonSkin .mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/TextAreaSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/TextInputSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/ToggleButtonSkin.mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/BorderSkin.mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/ButtonBarFirstButtonSkin .mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/ButtonBarLastButtonSkin. mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/ButtonSkin.mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/ComboBoxSkin.mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/DefaultButtonSkin.mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/EditableComboBoxSkin.mxm l
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/PanelBorderSkin.mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/PopUpButtonSkin.mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/SparkSkinForHalo.as
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/StepperDecrButtonSkin.mx ml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/StepperIncrButtonSkin.mx ml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/TextInputBorderSkin.mxml
        flex/sdk/trunk/frameworks/projects/wireframe/src/spark/skins/wireframe/ApplicationSkin.mx ml
        flex/sdk/trunk/frameworks/tests/basicTests/BasicTests.css
        flex/sdk/trunk/frameworks/tests/basicTests/spark/scripts/BorderTestScript.mxml
    Removed Paths:
        flex/sdk/trunk/frameworks/projects/framework/src/mx/logging/targets/MiniDebugTarget.as

    Gordon, it looks like its been a while since you made this post.  Not sure how valid it is now...   I am particularly interested in the LigatureLevel.NONE value.  It seems that it is no longer supported.
    How do I turn of ligatures in the font rendering?
    My flex project involves trying to match the font rendering of Apache's Batik rendering of SVG and ligatures have been turned off in that codebase.  Is there any way (even roundabout) to turn ligatures off in flash?
    Thanks,
    Om

  • Using HostComponent as target for effect in skin file

    Hi,
    I am creating a collapsible panel. I have the component file and a skin file.
    I have declared collapsed and normal states in my skin file.
    when the state change happens i need to show some animation, so used the transition effects. as below.
    <s:transitions>
          <s:Transition fromState="*" toState="collapsed">
             <s:Parallel duration="250" target="{hostComponent}">
                <s:Resize heightTo="{hostComponent.collapsedHeight}" />
             </s:Parallel>
          </s:Transition>
          <s:Transition fromState="*" toState="normal">
             <s:Parallel duration="250" target="{hostComponent}">
                <s:Resize heightTo="{hostComponent.expandedHeight}" />
             </s:Parallel>
          </s:Transition>
    </s:transitions>
    Everything works fine with this.
    someone suggested me that using hostComponent as target for the effect is not a good practice? are ther any disadvantages of this.
    I tried setting one of the group as target for the effect but that only resizes the particular group and not entire component. if i set the skin as target i.e. "this", still the component doesnot resize.
    any suggestions?

    Hi,
    I am creating a collapsible panel. I have the component file and a skin file.
    I have declared collapsed and normal states in my skin file.
    when the state change happens i need to show some animation, so used the transition effects. as below.
    <s:transitions>
          <s:Transition fromState="*" toState="collapsed">
             <s:Parallel duration="250" target="{hostComponent}">
                <s:Resize heightTo="{hostComponent.collapsedHeight}" />
             </s:Parallel>
          </s:Transition>
          <s:Transition fromState="*" toState="normal">
             <s:Parallel duration="250" target="{hostComponent}">
                <s:Resize heightTo="{hostComponent.expandedHeight}" />
             </s:Parallel>
          </s:Transition>
    </s:transitions>
    Everything works fine with this.
    someone suggested me that using hostComponent as target for the effect is not a good practice? are ther any disadvantages of this.
    I tried setting one of the group as target for the effect but that only resizes the particular group and not entire component. if i set the skin as target i.e. "this", still the component doesnot resize.
    any suggestions?

  • [svn:fx-trunk] 5170: Round 2 of bug fixes for the Spark skins for Halo components.

    Revision: 5170
    Author: [email protected]
    Date: 2009-03-04 17:50:32 -0800 (Wed, 04 Mar 2009)
    Log Message:
    Round 2 of bug fixes for the Spark skins for Halo components. Thanks to Alex for help with the data grid issues.
    Bugs fixed:
    SDK-19655 - Setting rowCount property on DataGrid causes extra blank row to be displayed
    SDK-19652 - Items in a DataGrid do not line up after scrolling.
    SDK-19605 - disabled Halo ColorPicker with Gumbo skin draws too dark
    SDK-19596 - When you have a single button on an Alert, the left edge looks flatter than the right
    SDK-19585 - Menus compiled with the halo theme in Flex 4 have a different backgroundColor than in Flex 3
    SDK-19665 - Halo List with Gumbo skin doesnt draw the alternating item color all the way to the right edge of the control if VScrollBar is present
    SDK-19651 - odd header rendering issue on Halo DataGrid with Gumbo skin
    QA Notes: The alert layout code was positioning the buttons/text on sub-pixel boundaries if the width or height of the alert was an odd number of pixels. We always snap to pixel boundaries now, but this may cause bitmap compare issues with Alert.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-19655
    http://bugs.adobe.com/jira/browse/SDK-19652
    http://bugs.adobe.com/jira/browse/SDK-19605
    http://bugs.adobe.com/jira/browse/SDK-19596
    http://bugs.adobe.com/jira/browse/SDK-19585
    http://bugs.adobe.com/jira/browse/SDK-19665
    http://bugs.adobe.com/jira/browse/SDK-19651
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/DataGrid.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/alertClasses/AlertForm.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/core/ScrollControlBase.as
    flex/sdk/trunk/frameworks/projects/halo/defaults.css
    flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/ColorPickerSkin.mxml

  • [svn:fx-trunk] 10024: Fix regressions from "More styles for Spark skins" checkin.

    Revision: 10024
    Author:   [email protected]
    Date:     2009-09-04 10:13:32 -0700 (Fri, 04 Sep 2009)
    Log Message:
    Fix regressions from "More styles for Spark skins" checkin.
    Remove redundant Group tag from BorderSkin
    Support borderStyle="none" for TextInputBorderSkin
    Made BorderSkin work correctly when borderStyle="none" and contentBackgroundColor is set
    QE notes: This should clean up a bunch of mustella failures
    Doc notes: None
    Bugs: SDK-23004, SDK-23008, SDK-23011
    Reviewer: Corey
    Tests run: checkintests, basictests
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-23004
        http://bugs.adobe.com/jira/browse/SDK-23008
        http://bugs.adobe.com/jira/browse/SDK-23011
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/framework/src/mx/core/Container.as
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/BorderSkin.mxml
        flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/TextInputBorderSkin.mxml

  • How to add add the code for the MouseEvent.CLICK event

    Could anyone help me who is a beginner please?
    I'd like to know step by step how to do the following
    instruction.
    I am trying to add a link to my flash.
    I drew a shape on the stage, select it and transform it to
    movie clip (hit F8 or right-click on it and select "Convert to
    symbol" from the popup menu or use the main menu: Modify ->
    Convert to symbol). I resized it as the same size as my stage, then
    make it transparent.
    Then I am supposed to do the following in order to create a
    link.
    "add the code for the MouseEvent.CLICK event that would open
    a url using the navigateToURL() function."
    But I just don't know how to. Could anyone tell me step by
    step approach please?
    Thanks in advance.

    Yes, click the frame where you have the button on stage and
    open the actions panel. paste the script in, and make sure whatever
    instance name you gave the button, you plug into the script. Also,
    the function declaration should be like so:
    function callFunction(e:MouseEvent):void{ <-- 'e' can be
    anything you want, it could be 'kfjeiwajfkd' for that
    matter.

  • [svn:fx-trunk] 5152: First pass of bug fixes for the Spark skins for Halo components.

    Revision: 5152
    Author: [email protected]
    Date: 2009-03-03 13:18:45 -0800 (Tue, 03 Mar 2009)
    Log Message:
    First pass of bug fixes for the Spark skins for Halo components.
    Bugs:
    SDK-19963 - themeColor should not affect rollOverColor or selectionColor in flex 4
    SDK-19654 - Spark skin for the Halo ComboBox dropdown needs a drop shadow
    SDK-19637 - Halo HScrollBar/VScrollBar controls dont render correctly when specifying includeIn states
    SDK-19634 - Halo ProgressBar default size is very different when using Halo vs Gumbo theme
    SDK-19626 - Flicker when toggling enabled property on Halo TabBar control with Gumbo skin
    SDK-19556 - selected Halo CheckBox and RadioButton icons briefly flicker when you roll over them
    SDK-19658 - Halo ComboBox with Gumbo skin has an odd flicker
    Doc/QA Notes: The fix for SDK-19963 includes a compatibility-version check. When compatibility-version < 4, setting themeColor implicitly sets rollOverColor and selectionColor, if they have not been set. When compatibility-version >= 4, you must explicitly set rollOverColor and selectionColor, even when using the Halo theme.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-19963
    http://bugs.adobe.com/jira/browse/SDK-19654
    http://bugs.adobe.com/jira/browse/SDK-19637
    http://bugs.adobe.com/jira/browse/SDK-19634
    http://bugs.adobe.com/jira/browse/SDK-19626
    http://bugs.adobe.com/jira/browse/SDK-19556
    http://bugs.adobe.com/jira/browse/SDK-19658
    http://bugs.adobe.com/jira/browse/SDK-19963
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/components/FxApplication.as
    flex/sdk/trunk/frameworks/projects/framework/defaults.css
    flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/Button.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/ComboBase.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/core/Application.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UIComponent.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/graphics/RectangularDropShadow.as
    flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/BorderSkin.mxml
    flex/sdk/trunk/frameworks/projects/sparkskins/src/mx/skins/spark/ProgressBarTrackSkin.mxm l

  • [svn:fx-trunk] 8652: Set ControlBar borderStyle to "none" for Spark skins.

    Revision: 8652
    Author:   [email protected]
    Date:     2009-07-16 17:16:28 -0700 (Thu, 16 Jul 2009)
    Log Message:
    Set ControlBar borderStyle to "none" for Spark skins.
    QE notes: -
    Doc notes: -
    Bugs: SDK-21399
    Reviewer: Jason
    Tests run: checkintests, QE cyclone
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-21399
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/framework/defaults.css

  • How to use swf file for Spark Skin

    Hi all
    I have little confuse about how to use swf file with Spark Skin,
    in Flex3 , i use Flex Skin Design Extension for Flash to deal with skin ,
    so basically , I just create a swf file and import to the project , then everything is ok
    but , seem that not working in flex4 , spark skin.
    1` I can't find the Flex Skin Design for the FlashCs4
    2` I try to use FlashCs3 version to import the skin art to the project , but seemed not working.
    3` I Google and check the Flex4 Help , seemed Spak skin need the Skin-Class , which I don't know how to use that with swf file
        what I have searched is how to use FXG , or some jpg file in that skin class, none of them are use swf file.
    so , is there any way that let user use the swf file to deal with the skin?
           is the Flex Skin Design can use in Flex4?
    Thanks

    Hello,
    I'm new to Flex, but have come to it from Flash Pro.  I'd like to know the same thing.  I think I found the answer here:
    http://www.flashallys.com/blog/spark-button-skinning-with-flash-symbols/
    However my question is now: Is this a good approach to use?
    99% of the googling I've done tells me to skin components with fxg files.  I've tried that by creating graphics and exporting from flash, but using swfs containing lots of graphics is much faster so I'd rather use that.
    The other thing I've done is to create custom components using these helpful tutorials:
    Creating component in flash:
    http://www.webkitchen.be/2008/12/12/video-tutorial-make-flex-components-with-flash-cs4/
    Dealing with Resizing with method overrides for your flash component:
    http://www.psyked.co.uk/flex/creating-flex-components-the-easy-way-for-flash-ide-converts. htm
    This allows me the flexibility of Flash Pro design with the layout, transistions, data binding etc from Flex.
    So my question is: Is this approach (skinning spark components with swfs, and using custom swc components made in flash) a bad idea for any reason?  E.g. does it create slow mobile apps?
    Cheers
    Chris

  • Targetting a button in flv skin

    Hi
    I want to be able to target a button that is within the skin for a flvplayback component. This is my first real adventure with AS3 and..... (feel like I want to scream!)
    In the library for the skin I get "fl.video.skin.FullScreenButtonOnOver" and paste this into the main timeline with some code like this.
    stop();
    function edward(event:MouseEvent):void{
    trace ("the button was pressed");
    fl.video.skin.FullScreenButtonOnOver.addEventListener(MouseEvent.CLICK, edward);
    which comes back with the error "Access of undefined property fl" - which doesn't surprise me really.
    What do I do to target taht button
    Thanks

    Thanks for reply
    My instance is called myVideo.
    so I do this:
    stop();
    function edward(event:MouseEvent):void{
         trace ("the button was pressed");
    myVideo.fullScreenButton.addEventListener(MouseEvent.CLICK, edward);
    ... lots more code...
    and still get an error. Is it something to do with the "delay" you mentioned?
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
         at index002_fla::MainTimeline/frame1()[index002_fla.MainTimeline::frame1:10]

  • Multiple Buttons in JTable Headers:  Listening for Mouse Clicks

    I am writing a table which has table headers that contain multiple buttons. For the header cells, I am using a custom cell renderer which extends JPanel. A JLabel and JButtons are added to the JPanel.
    Unfortunately, the buttons do not do anything. (Clicking in the area of a button doesn't appear to have any effect; the button doesn't appear to be pressed.)
    Looking through the archives, I read a suggestion that the way to solve this problem is to listen for mouse clicks on the table header and then determine whether the mouse clicks fall in the area of the button. However, I cannot seem to get coordinates for the button that match the coordinates I see for mouse clicks.
    The coordinates for mouse clicks seem to be relative to the top left corner of the table header (which would match the specification for mouse listeners). I haven't figured out how to get corresponding coordinates for the button. The coordinates returned by JButton.getBounds() seem to be relative to the top left corner of the panel. I hoped I could just add those to the coordinates for the panel to get coordinates relative to the table header, but JPanel.getBounds() gives me negative numbers for x and y (?!?). JPanel.getLocation() gives me the same negative numbers. When I tried JPanel.getLocationOnScreen(), I get an IllegalComponentStateException:
    Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
    Can someone tell me how to get coordinates for the button on the JTableHeader? Or is there an easier way to do this (some way to make the buttons actually work so I can just use an ActionListener like I normally would)?
    Here is relevant code:
    public class MyTableHeaderRenderer extends JPanel implements TableCellRenderer {
    public MyTableHeaderRenderer() {
      setOpaque(true);
      // ... set colors...
      setBorder(UIManager.getBorder("TableHeader.cellBorder"));
      setLayout(new FlowLayout(FlowLayout.LEADING));
      setAlignmentY(Component.CENTER_ALIGNMENT);
    public Component getTableCellRendererComponent(JTable table,
                                                     Object value,
                                                     boolean isSelected,
                                                     boolean hasFocus,
                                                     int row,
                                                     int column){
      if (table != null){
        removeAll();
        String valueString = (value == null) ? "" : value.toString();
        add(new JLabel(valueString));
        Insets zeroInsets = new Insets(0, 0, 0, 0);
        final JButton sortAscendingButton = new JButton("1");
        sortAscendingButton.setMargin(zeroInsets);
        table.getTableHeader().addMouseListener(new MouseAdapter(){
          public void mouseClicked(MouseEvent e) {
            Rectangle buttonBounds = sortAscendingButton.getBounds();
            Rectangle panelBounds = MyTableHeaderRenderer.this.getBounds();
            System.out.println(Revising based on (" + panelBounds.x + ", "
                               + panelBounds.y + ")...");
            buttonBounds.translate(panelBounds.x, panelBounds.y);
            if (buttonBounds.contains(e.getX(), e.getY())){  // The click was on this button.
              System.out.println("Calling sortAscending...");
              ((MyTableModel) table.getModel()).sortAscending(column);
            else{
              System.out.println("(" + e.getX() + ", " + e.getY() + ") is not within "
                                 + sortAscendingButton.getBounds() + " [ revised to " + buttonBounds + "].");
        sortAscendingButton.setEnabled(true);
        add(sortAscendingButton);
        JButton button2 = new JButton("2");
        button2.setMargin(zeroInsets);
        add(button2);
        //etc
      return this;
    }

    I found a solution to this: It's the getHeaderRect method in class JTableHeader.
    table.getTableHeader().addMouseListener(new MouseAdapter(){
      public void mouseClicked(MouseEvent e) {
        Rectangle panelBounds = table.getTableHeader().getHeaderRect(column);
        Rectangle buttonBounds = sortAscendingButton.getBounds();
        buttonBounds.translate(panelBounds.x, panelBounds.y);
        if (buttonBounds.contains(e.getX(), e.getY()) && processedEvents.add(e)){  // The click was on this button.
          ((MyTableModel) table.getModel()).sortAscending(column);
    });

  • Best practices for adding CLICK listeners to complicated menus?

    OK, I’m gonna wear out my welcome but here’s my last question of the day:
    I’ve got a project that is essentially a large collection of menus, some buttons common across multiple screens, others unique. The following link is the work in progress, most of the complexity is in the “Star Action Items and Forms” area (btw: the audio in the launch presentation is just a placeholder track, I know we can't use it):
    http://www.appliedcd.com/Be-A-star/Be-A-star.html
    To deal with the large number buttons my timeline simply has the following for every menu frame:
    stop();
    initFrame();
    The initFrame() function then has a list of frames and activates the buttons appearing on each screen, a very simplified example follows. In this example commonButtons span all 3 menus, semiCommonButtons span menu 2 and 3, button1A, button2A, etc… are unique per menu.:
    function initFrame():void {
         var myFrame:String = this.currentLabel;
         commonButton1.addEventListener(MouseEvent.CLICK,onInternalLink);
         commonButton2.addEventListener(MouseEvent.CLICK,onInternalLink);
         commonButton3.addEventListener(MouseEvent.CLICK,onInternalLink);
         switch(myFrame) {
              case "menu1":
                   button1A.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button1B.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button1C.addEventListener(MouseEvent.CLICK,onInternalLink);
              break;
              case "menu2":
                   semiCommonButton1.addEventListener(MouseEvent.CLICK,onInternalLink);
                   semiCommonButton2.addEventListener(MouseEvent.CLICK,onInternalLink);
                   semiCommonButton3.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button2A.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button2B.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button2C.addEventListener(MouseEvent.CLICK,onInternalLink);
              break;
              case "menu3":
                   button3A.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button3B.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button3C.addEventListener(MouseEvent.CLICK,onInternalLink);
              break;
    The way the project was designed, I “thought” menu3 would only be accessible through menu2, thus guaranteeing that the semiCommonButtons would get initialized, but I forgot the functionality of my back button could jump the user directly from menu1 to menu3. The solution is simple, initialize every button on every navigation  target, however, is this really the best way to initialize a bunch of buttons? Another possible approach would be to have an array of button instance names and a function that said: if instance XYZ exists, add listener, then simply loop through the array on every nav target. Anyone with more experience have advice on best practices in this situation?

    Hmmmm just run a test on this whereby I added the above snippet to my master page. I then publish a major version. I can see that every (Welcome) custom page layout has this data widget working, providing I add the div to the page..  
    I wonder if the reason I can't add the snippet  directly  to an individual custom layout page is a bug or am I doing something incorrectly?
    Daniel

  • [svn:fx-trunk] 8136: Adjustments to default size and padding for TextInput and TextArea skins.

    Revision: 8136
    Author:   [email protected]
    Date:     2009-06-23 16:16:49 -0700 (Tue, 23 Jun 2009)
    Log Message:
    Adjustments to default size and padding for TextInput and TextArea skins.
    TextInput default with is big enough to hold 10 characters (it will actually hold more than 10 "normal width" characters)
    TextArea padding matches TextInput padding
    These changes are done to the Spark and Wireframe skins.
    Bugs: SDK-16300 & SDK-16294
    QE Notes: New baseline bitmaps are needed (sorry Peter!)
    Doc Notes: None
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-16300
        http://bugs.adobe.com/jira/browse/SDK-16294
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/TextAreaSkin.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/skins/spark/TextInputSkin.mxml
        flex/sdk/trunk/frameworks/projects/wireframe/src/spark/skins/wireframe/TextAreaSkin.mxml
        flex/sdk/trunk/frameworks/projects/wireframe/src/spark/skins/wireframe/TextInputSkin.mxml

  • Visual (WYSIWYG) Spark Skinning

    Hi,
    I've been having a very tough time with the transition to the Spark components. I've already authored another post about trying to skin spark components with Flash, but I'm going to give this another shot. First, let me say that I am not exclusively a designer or a developer, but rather I have to do both ends of each project. With that said, this new spark skinning is creating an impossibly long and complicated workflow for me.
    I used to use the combination of the Flex Component kit in Flash and CSS to modify the appearance of all my components. I like it because from the design side, I knew exactly what my component would look like and if I wanted to modify it's appearance, I could use the Flash drawing tools to modify it, recompile the swc, and everything was just fine.
    While I understand the performance gains of the Spark architechture, I just think that it has come at the expense of smaller designer/developers like myself who have too much work to do already than to spend tons of time coding to modify the appearance of components. I know I am whining, which is probably because I'm more of a designer than developer, but the only solution I keep hearing is to use Flash Catalyst, which is no solution at all. The interface stinks, and the more I use it, the more I feel like a developer because it's like Flash with training wheels, and about as useful.
    I have only a couple of questions, now that I am done whining:
    1. Is there a workflow that exists between Illustrator or Flash and Flex for the purpose of skinning spark components (other than Catalyst) ? and:
    2. Is there a resource that can make sense of spark skinning and how to streamline the process ? (Learning how to create them and use skins) ?
    Flex 3 seemed so intuitive and my development time was so much quicker, that I am condsidering going back. I like to actually design my applications using design tools (Illustrator, Photoshop, and Flash). The notion that you can acheive the same result while using skins is absolutely crazy, and it doesn't make any sense. I'm not minimizing the benefits of spark in terms of performance and applying effects and animations on the fly, but the drawbacks far outweigh the benefits for me personally.

    I can't really help you pick the best MVC framework, but I can recommend that if you are moving your Flex 3 projects to Flex 4, make as few changes as possible for moving components right now.  Like you said, we are in the middle of a transition.  The Adobe guys recommend not porting all of your mx Projects over to Spark.  I have a large Flex 3 project that I'm almost finished moving to 4.1 and I have changed as little as possible.  The only reason I converted it was to take advantage of some of the nice things they've done with data services and binding.
    I don't think it is a waste of time to take Flex 3 projects and make them run in Flex 4.1 or higher, but I do think it is a waste of time to convert all of those components over to their Spark counterparts at this time.

  • How to disable MouseEvent.CLICK events on a MovieClip

    Hi all,
    I am new to Flash & ActionScript 3.0. I only have basic knowledge of AS 3.0 && Flash.
    My issue starts here:
                         Suppose, I created a MovieClip(with instance-name= "myClip") on the stage. If I need to process MouseEvent.CLICK event on this movieclip(myClip), then we use addEventListener(bla.... bla...); method.
                        Now, my requirement is, in certain case, I do not want to occur any MouseEvent.CLICK events on this same movieClip(i.e., myClip).Then, How to do this? (or) What is the method/class used in this context?
    PLEASE, CAN YOU REPLY ME WITH AN EXAMPLE....
    Please, can anyone help me in this context...
    Atlast, My requirement is: How to remove/disable Mouse_CLICK events when occur on a MovieCLip.
    It's urgent....
    Waiting for ur reply....
    Thanks in advance...
    Srihari.Ch

    you can remove the event listener with
    removeEventListener(bla.... bla...);
    but depending on what it is that you actually want to do (whatever determines your 'certain case') you could also set a boolean flag for example and just do something different in your listener function based on that value

Maybe you are looking for