开发者

multiple objects in flash (detecting object in event)

开发者 https://www.devze.com 2023-03-08 18:56 出处:网络
I want to create something like a scratch with 3 options. First website sends info about which field is correct. then flash replaces 2 movie clips with \'wrong\' image and 1 with \'good\' image. I alr

I want to create something like a scratch with 3 options. First website sends info about which field is correct. then flash replaces 2 movie clips with 'wrong' image and 1 with 'good' image. I already created scratch evect but in only works on 1 object. I don't know why?

I even tried duplication of event functions. Best way would be getting index of element. but how to pass it in event function?

Basically its just 3 black tiles with images on them. But why only the first object works?

My code is:

function getFlashVars():Object {
    return Object(LoaderInfo(this.loaderInfo).parameters);
}

var m = 0;

function stopRys(myszka:MouseEvent):void {
    m = myszka.currentTarget.tabIndex;
    cover[m].removeEventListener(MouseEvent.MOUSE_MOVE, tworzMaske);
    image[m].removeEventListener(MouseEvent.MOUSE_MOVE, tworzMaske);
}

function startRys(myszka:MouseEvent):void {
    m = myszka.currentTarget.tabIndex;
    cover[m].addEventListener(MouseEvent.MOUSE_MOVE, tworzMaske);
    image[m].addEventListener(MouseEvent.MOUSE_MOVE, tworzMaske);
}

function tworzMaske(myszka:MouseEvent):void {
    m = myszka.currentTarget.tabIndex;
    image[m].visible = true;
    rysuj[m].graphics.lineStyle(1);
    rysuj[m].graphics.beginFill(0x000000);
    rysuj[m].graphics.drawCircle(mouseX, mouseY, 50);
    image[m]开发者_运维百科.mask = rysuj[m];
}

var key1 = getFlashVars().key1;

var intWidth:Number = 200;
var intHeight:Number = 200;
var cover = new Array();
var image = new Array();
var rysuj = new Array();
var i:Number = 0;

for (i=0; i<3; i++) {
    cover[i] = new MovieClip();
    image[i] = new MovieClip();
    rysuj[i] = new Sprite();

    cover[i]._x = intWidth*i;
    cover[i]._y = 0;
    cover[i].tabIndex = i;
    cover[i]._width = intWidth;
    cover[i]._height = intHeight;
    cover[i].graphics.beginFill(0x000000);
    cover[i].graphics.drawRect(intWidth*i,0,intWidth,intHeight);
    cover[i].graphics.endFill();

    image[i]._x = intWidth*i;
    image[i]._y = 0;
    image[i].tabIndex = i;
    image[i]._width = intWidth;
    image[i]._height = intHeight;
    var myBitmapDataObject:przegrana = new przegrana(200, 200);
    var myImage:Bitmap = new Bitmap(myBitmapDataObject);
    image[i].addChild(myImage);

    addChild(cover[i]);
    addChild(image[i]);
    addChild(rysuj[i]);

    image[i].visible = false;

    image[i].addEventListener(MouseEvent.MOUSE_DOWN, startRys);
    cover[i].addEventListener(MouseEvent.MOUSE_DOWN, startRys);
    image[i].addEventListener(MouseEvent.MOUSE_OUT, stopRys);
    image[i].addEventListener(MouseEvent.MOUSE_UP, stopRys);

}

EDIT:

Now i have some wierd problem. Events work only on first object just like it would be on whole flash movie.


You "can't" pass custom arguments to even listeners. To know which object dispatched an event you can use myszka.target.

0

精彩评论

暂无评论...
验证码 换一张
取 消