1

ExtendedDateChooser 类是我的 flex 项目中使用的简单事件日历的绝佳解决方案。如果谷歌搜索“添加日历事件条目到灵活日期选择器组件”,您可以在帖子的评论中找到更新解决方案的链接。我在下面发布了文件。

该日历的问题是更改月份时缺少文本事件。

Actionscript 中是否有updateCompleted事件,就像在 dateChooser flex 组件中一样?像:

<mx:DateChooser id="dc" updateCompleted="goThroughDateChooserCalendarLayoutAndSetEventsInCalendarAgain()"</mx>

scroll添加事件时,它在 Actionscript 中可用,它被调度但在 updateDisplayList()被触发之后,所以没有设法回答,为什么日历事件被删除?

任何建议,在代码中添加什么,也许会覆盖某些功能?

ExtendedDateChooserClass.mxml

   <?xml version='1.0' encoding="utf-8"?>

   <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:mycomp="cyberslingers.controls.*" 
    layout="absolute"  
   creationComplete="init()">

   <mx:Script>


<![CDATA[
    import cyberslingers.controls.ExtendedDateChooser;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.events.FaultEvent;
    import mx.controls.Alert;

public var mycal:ExtendedDateChooser = new ExtendedDateChooser();

    // collection to hold date, data and label
    [Bindable]
    public var dateCollection:XMLList = new XMLList();

    private function init():void
    {
        eventList.send();
    }

    private function readCollection(event:ResultEvent):void
    {
        dateCollection = event.result.calendarevent;

        //Position and size the calendar
        mycal.width = 400;
        mycal.height = 400;
        //Add the data from the XML file to the calendar
        mycal.dateCollection = dateCollection;
        //Add the calendar to the canvas
        this.addChild(mycal);
    }

    private function readFaultHandler(event:FaultEvent):void
    {
        Alert.show(event.fault.message, "Could not load data");
    }
]]>
</mx:Script>

<mx:HTTPService id="eventList"
      url="data.xml"
      resultFormat="e4x"
      result="readCollection(event);"
      fault="readFaultHandler(event);"/>

 </mx:Application>

ExtendedDateChooser.as

package cyberslingers.controls
{
import flash.events.Event;
import flash.events.TextEvent;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.CalendarLayout;
import mx.controls.DateChooser;
import mx.core.UITextField;
import mx.events.FlexEvent;



public class ExtendedDateChooser extends DateChooser
{
    public function ExtendedDateChooser()
    {
        super();
        this.addEventListener(TextEvent.LINK, linkHandler);
        this.addEventListener(FlexEvent.CREATION_COMPLETE, addEvents);
    }

    //datasource
    public var dateCollection:XMLList = new XMLList();

    //--------------------------------------
    //  Add events
    //--------------------------------------
    /**
     * Loop through calendar control and add event links
     * @param e
     */ 
    private function addEvents(e:Event):void
    {
        // loop through all the calendar children
        for(var i:uint = 0; i < this.numChildren; i++)
        {
            var calendarObj:Object = this.getChildAt(i);

            // find the CalendarLayout object
            if(calendarObj.hasOwnProperty("className"))
            {
                if(calendarObj.className == "CalendarLayout")
                {
                    var cal:CalendarLayout = CalendarLayout(calendarObj);

                    // loop through all the CalendarLayout children
                    for(var j:uint = 0; j < cal.numChildren; j++)
                    {
                        var dateLabel:Object = cal.getChildAt(j);

                        // find all UITextFields
                        if(dateLabel.hasOwnProperty("text"))
                        {
                            var day:UITextField = UITextField(dateLabel);

                            var dayHTML:String = day.text;
                            day.selectable = true;
                            day.wordWrap = true;
                            day.multiline = true;
                            day.styleName = "EventLabel";

                            //TODO: passing date as string is not ideal, tough to validate
                            //Make sure to add one to month since it is zero based
                            var eventArray:Array = dateHelper((this.displayedMonth+1) + "/" + dateLabel.text + "/" + this.displayedYear);
                            if(eventArray.length > 0)
                            {

                                for(var k:uint = 0; k < eventArray.length; k++)
                                {
                                    dayHTML += "<br><A HREF='event:" + eventArray[k].data + "' TARGET=''>" + eventArray[k].label + "</A>";
                                }
                                day.htmlText = dayHTML;
                            }
                        }
                    }
                }
            }
        }
    }

    //--------------------------------------
    //  Events
    //--------------------------------------
    /**
     * Handle clicking text link
     * @param e
     */ 
    private function linkHandler(event:TextEvent):void
    {
        // What do we want to do when user clicks an entry?
        Alert.show("selected: " + event.text);
    }

    //--------------------------------------
    //  Helpers
    //--------------------------------------
    /**
     * Build array of events for current date
     * @param string - current date
     * 
     */ 
    private function dateHelper(renderedDate:String):Array
    {
        var result:Array = new Array();
        for(var i:uint = 0; i < dateCollection.length(); i++)
        {
            if(dateCollection[i].date == renderedDate)
            {
                result.push(dateCollection[i]);
            }
        }
        return result;
    }

}
}

数据.xml

<?xml version="1.0" encoding="utf-8"?>
<rss>

<calendarevent>
<date>8/22/2009</date>
<data>This is  a test 1</data>
<label>Stephens Test 1</label>
</calendarevent>

<calendarevent>
<date>8/23/2009</date>
<data>This is  a test 2</data>
<label>Stephens Test 2</label>
</calendarevent>

</rss>
4

1 回答 1

0

只需FlexEvent.CREATION_COMPLETE将 ExtendedDateChooser.as 中的更改为FlexEvent.UPDATE_COMPLETE

应该这样做。

于 2010-09-20T12:22:48.757 回答