Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   Ошибка addChild со спрайтом (http://www.flasher.ru/forum/showthread.php?t=192262)

fd96 11.01.2013 09:02

Ошибка addChild со спрайтом
 
Есть 2 класса , один Базовый и один добавочный , спрайты в базовом создаются и ложатся друг на друга ровно, но нужно добавить на базовый слой спрайт из нового класса. Ничего не умею советам буду рад.
мой код :
Основной:
Код AS3:

package
{
        import flash.display.*;
        import flash.events.*;
        import flash.ui.*;
        import flash.utils.*;
 
        import mx.core.*;
 
        public class Game1 extends Sprite
        {
                public var spr1:Sprite = new Sprite;
                public var spr2:Shape = new Shape;
                public var dnco:Shape = new Shape;
                public var upco:Shape = new Shape;
                public var rico:Shape = new Shape;
                public var leco:Shape = new Shape;
                public var map:Mapcreate = null;
                public function Game1()
                {
                        spr1.graphics.beginFill(0x00412A, 1);
                        spr1.graphics.drawRect(-300, 0, 1800, 400);
                        spr1.graphics.endFill();
                        addChild(spr1);
                        creation();
                        addChild(spr2);
                        makesen();
                        addChild(leco);
                        addChild(dnco);
                        addChild(upco);
                        addChild(rico);
                        addChild(map.Verwal1);
                }
                public function creation():void
                {
                        spr2.graphics.beginFill(0x00AAFF, 0.5);
                        spr2.graphics.drawRect(0, 0, 30, 50);
                        spr2.graphics.endFill();
                        spr2.x = 30;
                        spr2.y = 300;
                        spr2.width=30;
                        spr2.height=50;
                }
                public function makesen():void
                {
                        dnco.graphics.beginFill(0x222222, 0.5);
                        dnco.graphics.drawRoundRect(0, 0, 20, 5, 5, 5);
                        dnco.graphics.endFill();
                        dnco.x = spr2.x+5;
                        dnco.y = spr2.y+45;
                        dnco.width=20;
                        dnco.height=5;
 
                        upco.graphics.beginFill(0x222222, 0.5);
                        upco.graphics.drawRoundRect(0, 0, 20, 5, 5, 5);
                        upco.graphics.endFill();
                        upco.x = spr2.x+5;
                        upco.y = spr2.y;
                        upco.width=20;
                        upco.height=5;
 
                        rico.graphics.beginFill(0x222222, 0.5);
                        rico.graphics.drawRoundRect(0, 0, 5, 45, 5, 5);
                        rico.graphics.endFill();
                        rico.x = spr2.x+25;
                        rico.y = spr2.y+2;
                        rico.width=5;
                        rico.height=45;
 
                        leco.graphics.beginFill(0x222222, 0.5);
                        leco.graphics.drawRoundRect(0, 0, 5, 45, 5, 5);
                        leco.graphics.endFill();
                        leco.x = spr2.x;
                        leco.y = spr2.y+2;
                        leco.width=5;
                        leco.height=45;
                }
        }
}

Второй класс:
Код AS3:

package
{
        import flash.display.*;
        import flash.events.*;
        import flash.ui.*;
        import flash.utils.*;
 
        public dynamic class Mapcreate extends Sprite
        {
                public var main:Game1;
                public var Verwal1:Sprite = new Sprite;
                public function Mapcreate()
                {
                        super();
                        blocks();
                }
                        public function blocks():void
                        {
                        Verwal1.graphics.beginFill(0x222222, 0.5);
                        Verwal1.graphics.drawRoundRect(0, 0, 600, 50, 15, 15);
                        Verwal1.graphics.endFill();
                        addChild(Verwal1);
                        }
        }
}


Wolsh 11.01.2013 09:44

Цитата:

public var map:Mapcreate = null;
//....
addChild(map.Verwal1);
У null нет свойства Verwal1.

fd96 11.01.2013 09:49

Я уже понял, но вот как поправить не понял, как дать верную ссылку на DisplayObject?

Condorcet 11.01.2013 10:05

Наверное нужно просто создать объект :)
Код AS3:

public var map:Mapcreate = Mapcreate()


fd96 11.01.2013 10:11

Если так сделать , то получаю ошибку 1136 - неверное колличество аргументов Mapcreate();
так что вопрос всё ещё в силе.

Astraport 11.01.2013 10:22

Код AS3:

public var map:Mapcreate = new Mapcreate();


fd96 11.01.2013 10:30

Благодарю , а то своими силами уже третьи сутки не мог сделать это , теперь можно пойти поспать.


Часовой пояс GMT +4, время: 21:16.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2024, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.