문제

파일 이름과 썸네일을 표시하고 파일을 로드/재생하는 버튼이 있는 구성 요소를 작성했습니다.구성 요소가 반복기에 데이터 바인딩되어 있습니다.버튼 이벤트가 기본 응용 프로그램에 실행되어 재생할 파일을 알려주도록 하려면 어떻게 해야 합니까?

도움이 되었습니까?

해결책

사용자 정의 구성 요소에서 버튼 클릭 이벤트를 수신한 다음 재생하려는 파일에 대한 정보가 포함된 사용자 정의 이벤트를 생성할 수 있습니다.그런 다음 이벤트에서 bubble 속성을 true로 설정하고 사용자 정의 구성 요소에서 사용자 정의 이벤트를 전달할 수 있습니다.bubble 속성을 사용하면 이벤트가 표시 목록에 떠서 기본 애플리케이션에 도달하게 됩니다.이제 기본 애플리케이션에서 해당 이벤트를 수신하고 올바른 파일을 재생할 수 있습니다.도움이 되었기를 바랍니다.

다른 팁

(드디어) 알아냈어

맞춤형 구성요소

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" x="0" y="0" width="215" height="102" styleName="leftListItemPanel" backgroundColor="#ECECEC" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Script>
    <![CDATA[
        [Bindable] public var Title:String = "";
        [Bindable] public var Description:String = "";
        [Bindable] public var Icon:String = ""; 
        [Bindable] public var FileID:String = "";
        private function viewClickHandler():void{
            dispatchEvent(new Event("viewClick", true));// bubble to parent
        }
    ]]>
</mx:Script>
<mx:Metadata>
    [Event(name="viewClick", type="flash.events.Event")]
</mx:Metadata>
<mx:Label x="11" y="9" text="{String(Title)}" styleName="listItemLabel"/>
<mx:TextArea x="11" y="25" height="36" width="170" backgroundAlpha="0.0" alpha="0.0" styleName="listItemDesc" wordWrap="true" editable="false" text="{String(Description)}"/>
<mx:Button x="20" y="65" label="View" click="viewClickHandler();" styleName="listItemButton" height="22" width="60"/>
<mx:LinkButton x="106" y="68" label="Details..." styleName="listItemLink" height="18"/>
<mx:HRule x="0" y="101" width="215"/>

리피터

<mx:Canvas id="pnlSpotlight" label="SPOTLIGHT" height="100%" width="100%" horizontalScrollPolicy="off">
    <mx:VBox width="100%" height="80%" paddingTop="2" paddingBottom="1"  verticalGap="1">
        <mx:Repeater id="rptrSpotlight" dataProvider="{aSpotlight}">            
            <sm:SmallCourseListItem 
                viewClick="PlayFile(event.currentTarget.getRepeaterItem().fileName);"
                Description="{rptrSpotlight.currentItem.fileDescription}"
                FileID = "{rptrRecentlyViewed.currentItem.fileName}"    
                Title="{rptrSpotlight.currentItem.fileTitle}" />
        </mx:Repeater>
    </mx:VBox>
</mx:Canvas>

핸들링 기능

private function PlayFile(fileName:String):void{
    Alert.show(fileName.toString());
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top