用as3动态添加组件

通过as代码动态添加组件的方法

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
 <s:layout>
  <s:BasicLayout/>
 </s:layout>
 <fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
 </fx:Declarations>
 <fx:Script>
  <![CDATA[
   import mx.controls.Image;
   public function addimage(Evt:MouseEvent):void
   {
    var image:Image=new Image();
    image.source="asset/ardcor.png";
    image.width=300;
    image.height=200;
    hbox.addChild(image);
      }
  ]]>
 </fx:Script>
 <mx:HBox id="hbox" x="-1" y="46">
  
 </mx:HBox>
 <s:Button click="addimage(event)" x="10" y="-1"/>
</s:Application>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目录 第 1 章 : 简介 目标读者 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 系统要求 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 关于本文档 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 印刷惯例 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 本手册中使用的术语 . . . . . . . . . . . . . . . . . . . . . . . . 2 其他资源 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 第 2 章 : 关于 ActionScript 3.0 组件 使用组件的优点 . . . . . . . . . . . . . . . . . . . . . . . . . . 3 组件类型 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 在文档中添加和删除组件 . . . . . . . . . . . . . . . . . . . . . . 5 查找组件的版本 . . . . . . . . . . . . . . . . . . . . . . . . . . 7 ActionScript 3.0 事件处理模型 . . . . . . . . . . . . . . . . . . . 7 一个简单的应用程序 . . . . . . . . . . . . . . . . . . . . . . . . 8 第 3 章 : 使用组件 组件体系结构 . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 使用组件文件 . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 调试组件应用程序 . . . . . . . . . . . . . . . . . . . . . . . . . 17 设置参数和属性 . . . . . . . . . . . . . . . . . . . . . . . . . . 17 库 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 调整组件大小 . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 实时预览 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 处理事件 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 使用显示列表 . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 使用 FocusManager . . . . . . . . . . . . . . . . . . . . . . . . 23 使用基于 List 的组件 . . . . . . . . . . . . . . . . . . . . . . . 24 使用 DataProvider . . . . . . . . . . . . . . . . . . . . . . . . 24 使用 CellRenderer . . . . . . . . . . . . . . . . . . . . . . . . 31 使组件具有辅助功能 . . . . . . . . . . . . . . . . . . . . . . . . 37 第 4 章 : 使用 UI 组件 使用 Button 组件 . . . . . . . . . . . . . . . . . . . . . . . . . 39 使用 CheckBox 组件 . . . . . . . . . . . . . . . . . . . . . . . . 41 使用 ColorPicker 组件 . . . . . . . . . . . . . . . . . . . . . . .43 使用 ComboBox 组件 . . . . . . . . . . . . . . . . . . . . . . . . 45 使用 DataGrid 组件 . . . . . . . . . . . . . . . . . . . . . . . . 48 使用 Label 组件 . . . . . . . . . . . . . . . . . . . . . . . . . 53 使用 List 组件 . . . . . . . . . . . . . . . . . . . . . . . . . . 55 使用 NumericStepper 组件 . . . . . . . . . . . . . . . . . . . . . 59 使用 ProgressBar 组件 . . . . . . . . . . . . . . . . . . . . . . 61 使用 RadioButton 组件 . . . . . . . . . . . . . . . . . . . . . . 66 使用 ScrollPane 组件 . . . . . . . . . . . . . . . . . . . . . . . 69 使用 Slider 组件 . . . . . . . . . . . . . . . . . . . . . . . . . 71 使用 TextArea 组件 . . . . . . . . . . . . . . . . . . . . . . . . 73 使用 TextInput 组件 . . . . . . . . . . . . . . . . . . . . . . . 76 使用 TileList 组件 . . . . . . . . . . . . . . . . . . . . . . . . 78 使用 UILoader 组件 . . . . . . . . . . . . . . . . . . . . . . . . 81 使用 UIScrollBar 组件 . . . . . . . . . . . . . . . . . . . . . . .82 第 5 章 : 自定义 UI 组件 关于 UI 组件自定义 . . . . . . . . . . . . . . . . . . . . . . . . 85 设置样式 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 关于外观 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 自定义 Button 组件 . . . . . . . . . . . . . . . . . . . . . . . . 89 自定义 CheckBox 组件 . . . . . . . . . . . . . . . . . . . . . . . 91 自定义 ColorPicker 组件 . . . . . . . . . . . . . . . . . . . . . 93 自定义 ComboBox 组件 . . . . . . . . . . . . . . . . . . . . . . . 94 自定义 DataGrid 组件 . . . . . . . . . . . . . . . . . . . . . . . 96 自定义 Label 组件 . . . . . . . . . . . . . . . . . . . . . . . . 100 自定义 List 组件 . . . . . . . . . . . . . . . . . . . . . . . . 101 自定义 NumericStepper 组件 . . . . . . . . . . . . . . . . . . . 104 自定义 ProgressBar 组件 . . . . . . . . . . . . . . . . . . . . . 105 自定义 RadioButton 组件 . . . . . . . . . . . . . . . . . . . . . 107 自定义 ScrollPane 组件 . . . . . . . . . . . . . . . . . . . . . 108 自定义 Slider 组件 . . . . . . . . . . . . . . . . . . . . . . . 109 自定义 TextArea 组件 . . . . . . . . . . . . . . . . . . . . . . 110 自定义 TextInput 组件 . . . . . . . . . . . . . . . . . . . . . . 112 自定义 TileList 组件 . . . . . . . . . . . . . . . . . . . . . . 113 自定义 UILoader 组件 . . . . . . . . . . . . . . . . . . . . . . 115 自定义 UIScrollBar 组件 . . . . . . . . . . . . . . . . . . . . . 115 第 6 章 : 使用 FLVPlayback 组件 使用 FLVPlayback 组件 . . . . . . . . . . . . . . . . . . . . . . 117 自定义 FLVPlayback 组件 . . . . . . . . . . . . . . . . . . . . . 132 使用 SMIL 文件 . . . . . . . . . . . . . . . . . . . . . . . . . 141 第 7 章 : 使用 FLVPlayback 字幕组件 使用 FLVPlaybackCaptioning 组件 . . . . . . . . . . . . . . . . . 148 使用 Timed Text 字幕 . . . . . . . . . . . . . . . . . . . . . . 150 将提示点用于字幕 . . . . . . . . . . . . . . . . . . . . . . . . 155
在Vue3中使用TypeScript获取动态组件component实例调用里面组件的方法,可以先通过 `ref` 获取动态组件的实例,再通过 `as` 关键字将其转换为具体的子组件类型,从而调用子组件中的方法。 例如,假设有一个动态组件 `MyComponent`,其中包含了一个子组件 `ChildComponent`,并且我们需要在父组件中获取 `ChildComponent` 实例并调用其方法。可以使用如下代码: ```vue <template> <div> <component :is="selectedComponent" ref="myComponent"></component> <button @click="handleClick">Call Child's Method</button> </div> </template> <script lang="ts"> import { defineComponent, ref } from 'vue' import ChildComponent from './ChildComponent.vue' export default defineComponent({ components: { ChildComponent }, data() { return { selectedComponent: 'ChildComponent' } }, setup() { const myComponentRef = ref<MyComponent | null>(null) const handleClick = () => { const childComponent = myComponentRef.value?.$refs.child as ChildComponent if (childComponent) { childComponent.doSomething() } } return { myComponentRef, handleClick } } }) </script> ``` 在上面的代码中,我们使用 `ref` 将动态组件 `MyComponent` 的实例绑定到 `myComponentRef` 变量上,并使用 `as` 关键字将其类型转换为 `MyComponent | null`。然后,在 `handleClick` 方法中,我们通过 `myComponentRef.value?.$refs.child` 获取到子组件 `ChildComponent` 的实例,并将其类型转换为 `ChildComponent`。最后,我们就可以调用 `ChildComponent` 中的方法了。 需要注意的是,在模板中使用 `ref` 时,需要添加一个 `.value` 后缀来访问 `ref` 变量所引用的对象。例如,上面的代码中,我们通过 `myComponentRef.value?.$refs.child` 来获取子组件 `ChildComponent` 的实例。 另外,如果子组件中的方法需要访问子组件的数据或者方法,可以使用 `provide` 和 `inject` 方法来实现。具体使用方法可以参考 Vue3 官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值