سؤال

لقد كتبت مكونًا يعرض اسم ملف وصورة مصغرة ويحتوي على زر لتحميل/تشغيل الملف.يتم ربط المكون بمكرر البيانات.كيف يمكنني تفعيل حدث الزر في التطبيق الرئيسي وإخباره بالملف الذي سيتم تشغيله؟

هل كانت مفيدة؟

المحلول

في المكون المخصص الخاص بك، يمكنك الاستماع إلى حدث النقر على الزر ثم إنشاء حدث مخصص يحتوي على معلومات حول الملف الذي تريد تشغيله.يمكنك بعد ذلك تعيين خاصية الفقاعات على "صحيح" في الحدث وإرسال الحدث المخصص من المكون المخصص الخاص بك.ستجعل خاصية الفقاعات الحدث الخاص بك يطفو على قائمة العرض ويصل إلى تطبيقك الرئيسي.الآن على تطبيقك الرئيسي يمكنك الاستماع إلى هذا الحدث وتشغيل الملف الصحيح.أتمنى أن يساعدك هذا.

نصائح أخرى

اكتشفت ذلك (أخيرًا)

مكون مخصص

<?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