• Lingo11 继承和child管理


    Movie中的parent script cast member,使用它,必须以new出一个child的形式。

    对单个movie,Director提供了一个列表用来管理movie中的child,the actorlist。要注意,这个actorlist并不是在new(script "parentname")之后自动更新。那么它存在的意义是什么捏?

    The ActorList

    在验证各种system event的触发顺序部分(http://www.cnblogs.com/mumuliang/archive/2011/11/04/2235763.html

    普通帧内几个系统事件的顺序是:

    beginSprite(本) à stepFrame à prepareFrame à enterFrame à exitFrame à endSprite(本

    第二个stepFrame在frame behavior中没有被响应。

    之所以没被响应,是因为stepFrame并不是frame behavior的system event,而是parent script的event。

    同时,也并不是所有parent script都会受到stepFrame event的message,只有在the actorlist中的child,Director才会向它发送stepframe event message。

    The actorlist用来维护要接受stepframe event message的child

    另外,Director在任何时候都不会主动清理actorlist,因此,需要lingoer自己确定并落实在何时清理actorlist。

    The actorlist = []

    Ancestor

    Lingo号称面向对象,它的多态是如何实现的?就是使用这个特殊的property,ancestor。

    用法,步骤:

    1. 首先给这个parent script顶一个property ancestor,必须叫这个名字。

    2. 在某处,通常会是new中给ancestor 赋值为父parent的实例(也就是父parent的child object)。

    -- womanscript

    property ancestor

    on new me, _name

      set ancestor to new (script "personscript", _name)

      return me

    end

    若personscript中实现了on setFrame me;同时,movie script中,prepareMovie中向actorlist添加了new womanscript。那么在每帧进入前,personscript中的setFrame都会执行。

    Personscript:

    property p_name

    on new me, _name

      p_name = _name

      put "person:" && p_name && "created"

      return me

    end 

    on stepFrame me

      put "person:" && p_name && "stepFrame"

    end

    Movie

    on prepareMovie

      the actorlist = []

      add the actorlistnew(script "womanscript""liang")

    end

    注意: 继承的是hanlder不是function。

    同时ancenstor的property也被全部继承。

  • 相关阅读:
    前端知识体系
    DOMContentLoaded与load的区别
    最佳网页宽度及其实现
    一些颜色工具网站
    Firebug入门指南
    CSS中背景图片定位方法
    字符编码笔记:ASCII,Unicode 和 UTF-8
    学JS的书籍
    深入理解定位父级offsetParent及偏移大小
    event——事件对象详解
  • 原文地址:https://www.cnblogs.com/mumuliang/p/2242146.html
Copyright © 2020-2023  润新知