PDA

Просмотр полной версии : Отмена обработчиков событий


zevvs
18.01.2006, 16:00
Есть несколько вложенных MovieClip, у которых реализованы и активированы обработчики объекта Stage, события onResize. В одном из обработчиков может наступить такая ситуация, что выполнять остальные обработчики в очереди не нужно. Можно ли прервать очередь обработки, (понятно, что можно использовать глобальные флаги, но это нежелательно).

KidsKilla
18.01.2006, 16:19
зависит от реализации.
подробней с примером объяснишь?

silin
18.01.2006, 16:33
загнать всю (для всех мувиков) обработку onResize в одну функцию, а уж из нее выйти, если 'наступить такая ситуация', не вопрос..

zevvs
19.01.2006, 07:29
загнать всю (для всех мувиков) обработку onResize в одну функцию, а уж из нее выйти, если 'наступить такая ситуация', не вопрос..
...Однако...А так же выкинуть все классы MovieClip-ов и делать все в 1-м кадре... ;)

zevvs
19.01.2006, 07:38
зависит от реализации.
подробней с примером объяснишь?
Попробую. Основной клип - какая-то рамка. Она должна тянуться по экану, но если Stage.width > 800. Ну допустим так:

/**
* Main Border View Class
*/

class MainBorderView extends MovieClip
{
function MainBorderView()
{
Stage.addListener(this);
onResize();
}
// ..... пропустим для нагладности логику клипа .... //
function onResize()
{
if (Stage.width > 800) {

trace('MainBorderView::onResize');
_xscale = 100;
_yscale = 100;
_width = Stage.width;
_height = Stage.height - 10;
_x = 0;
_y = 0;
} else {
/// ТУТ НАДО ЗАРУБИТЬ ОБРАБОТЧИКИ
}
}
}



Ну и где-то во вложенном в рамку клипе имеем:



class IntroPageView extends MovieClip
{
var isFirstFrame = true;
var enterBtn;
var service;
var image: MovieClip;
var bodyText: TextField;
var headText:TextField;
/**
* skin settings from xml
*/
var _screen = {width: 1024, height: 768};
var _image = {top:64, width: 400, leftMargin: 25, rightMargin: 25, height:400}
var _bodyText = {bottomMargin:80, rightMargin:40, color: 0x54534C, size: 20, font: "Verdana"};
var _headText = {bottomMargin:20, top: 64, color: 0x495E85, size: 30, font: "Verdana"};
var _enterBtn = {width: 100, height: 20, rightMargin: 40, bottomMargin: 40};
/*---------------------*/

function onEnterFrame()
{
if (isFirstFrame) {

isFirstFrame = false;
Stage.addListener(this);
}
}


function IntroPageView()
{
var mcl:MovieClipLoader = new MovieClipLoader();

enterBtn.onRelease = function() {
var galleriesListPage = new GalleriesListPage(_parent._parent);
_parent.removeMovieClip();
}

createEmptyMovieClip('image', 100);
var o:Object = new Object;
o.onLoadComplete = function (mc:MovieClip) {
mc.first = true;
mc.onEnterFrame = function () {

if (mc.first == true) {

_parent.visible = false;
_parent.onResize();
_parent.visible = true;
mc.first = false;
}
}
}
mcl.addListener(o);
mcl.loadClip(service.image, image);

createTextField('headText', 1, 0, 0, 0, 0);
headText.multiline = false;
headText.text = service.title;

createTextField('bodyText', 2, 0, 0, 0, 0);
bodyText.multiline = true;
bodyText.text = service.body;
}

function onResize()
{
trace('IntroPageView::onResize');
_xscale = 100;
_yscale = 100;
/**
* Set image position
*/
{
var p:Object = {x: _image.leftMargin, y:_image.top};
this.globalToLocal(p);
var p2:Object = {x: _image.width, y: _image.height};
this.globalToLocal(p2);
image._x = p.x;
image._y = p.y;
image._width = p2.x;
image._height = p2.y;
}
/**
* Set title position
*/
{
var f:TextFormat = new TextFormat();
f.size = _headText.size;
f.color = _headText.color;
f.font = _headText.font;
headText.setTextFormat(f);

var startX = _image.width + _image.leftMargin + _image.rightMargin;
var p:Object = {x: startX, y: _headText.top};
this.globalToLocal(p);
var p2:Object = {x: (Stage.width - startX - _bodyText.rightMargin), y: 0};
this.globalToLocal(p2);
headText.autoSize = true;
headText.wordWrap = false;
headText._x = p.x;
headText._y = p.y;
headText.width = p2.x;
}

/**
* Set intro text position and scale
*/
{
var f:TextFormat = new TextFormat();
f.size = _bodyText.size;
f.color = _bodyText.color;
f.font = _bodyText.font;
bodyText.setTextFormat(f);

var startX = _image.width + _image.leftMargin + _image.rightMargin;
var startY = _headText.top + headText._height + _headText.bottomMargin;
var p:Object = {x: startX, y: startY};
this.globalToLocal(p);
var p2:Object = {x: (Stage.width - startX - _bodyText.rightMargin), y: (Stage.height - startY - _bodyText.bottomMargin)};
this.globalToLocal(p2);
bodyText.autoSize = false;
bodyText.wordWrap = true;
bodyText._x = p.x;
bodyText._y = p.y;
bodyText._width = p2.x;
bodyText._height = p2.y;
}

/**
* Set button
*/
{
var startX = Stage.width - _enterBtn.rightMargin - _enterBtn.width;
var p:Object = {x: startX, y: (Stage.height - _enterBtn.bottomMargin)};
this.globalToLocal(p);
enterBtn._x = p.x;
enterBtn._y = p.y;

var p2:Object = {x: _enterBtn.width, y: _enterBtn.height};
this.globalToLocal(p2);
enterBtn._width = p2.x;
enterBtn._height = p2.y;
}
}
}



Вот именно onResize для этого класса (как и для остальных) хотелось бы зарубать... Автоматически, а не глобальными флажками.

silin
19.01.2006, 11:14
вариант: за Stage следит основной (frame_mc, например), он же
вещает когда надо (когда не надо не вещает), остальные слушают (и повинуются)
class MainBorderView extends MovieClip
{
private var broadcastMessage;
function MainBorderView ()
{
Stage.addListener (this);
AsBroadcaster.initialize (this);
onResize ();
}
private function onResize ()
{
if (Stage.width > 800)
{
trace (this + ':MainBorderView: resize');
broadcastMessage ("resize");
}
}
}
/////////////////////////////
class IntroPageView extends MovieClip
{
function IntroPageView ()
{
_root.frame_mc.addListener (this);
}
private function resize ()
{
trace (this + ':IntroPageView::Resize');
}
}