ExtendedDateChooser 클래스는 내 flex 프로젝트에서 사용되는 간단한 이벤트 캘린더를위한 훌륭한 솔루션입니다. "Upload-Calendar-Event-Entries-to-the-Flex-DateChooser- 구성 요소"에 대한 구글의 경우 게시물의 주석에 업데이트 된 솔루션 링크가 있습니다. 아래 파일을 게시했습니다.플렉스 액션 스크립트 확장 DateChooser, 캘린더 이벤트
달이 바뀌면 일정이 텍스트 이벤트가 누락됩니다.
dateChooser flex 구성 요소와 마찬가지로 Actionscript에 updateCompleted
이벤트가 있습니까? 에서와 마찬가지로 : scroll
이벤트가 액션 스크립트에서 사용할 수 인 추가
<mx:DateChooser id="dc" updateCompleted="goThroughDateChooserCalendarLayoutAndSetEventsInCalendarAgain()"</mx>
, 그것은 해고
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;
}
}
}
인 data.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>
감사합니다. :) 그건 내 문제를 해결. – Nemi