Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

* | |

  Show Posts
Pages: 1 2 3 [4]
46  Announcements and General Discussion / Architecture / Re: sendNotification EventListener Bug on: January 21, 2008, 06:27:44
Here is the MenuMediator class...

:
package com.prettypolly.view
{
import flash.utils.getDefinitionByName;
import flash.display.MovieClip;   
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import fl.events.ColorPickerEvent;
import flash.geom.Rectangle;
import flash.display.Stage;

    import org.puremvc.interfaces.*;
    import org.puremvc.patterns.mediator.Mediator;

    import com.prettypolly.ApplicationFacade;
import com.prettypolly.model.CategoriesDataProxy;
import com.prettypolly.view.components.Menu;
import com.prettypolly.view.*;
import flash.text.TextFieldAutoSize;
import flash.text.TextField;
import flash.text.TextFormat;
   
    /**
     * A Mediator for interacting with the LoadingScreen.
     */
    public class MenuMediator extends Mediator implements IMediator
    {
public static const NAME:String = 'MenuMediator';

private static const TOP_PADDING:int = 70;
private var menuItemCount:int = 0;

private var categoriesDataProxy:CategoriesDataProxy;

        public function MenuMediator(viewComponent:Object)
        {
            super(viewComponent);
   
categoriesDataProxy = facade.retrieveProxy(CategoriesDataProxy.NAME) as CategoriesDataProxy;
        }

protected function get menu():MenuMC
{
            return viewComponent as MenuMC;
        }

        override public function getMediatorName():String
        {
            return MenuMediator.NAME;
        }

        override public function listNotificationInterests():Array
        {
return [
ApplicationFacade.MENU_CATEGORIES_LOADED
];
        }

override public function handleNotification(note:INotification):void
        {
switch (note.getName())
{
// Application Updates

// Proxy Updates
case ApplicationFacade.MENU_CATEGORIES_LOADED:
buildMenuItems();
break;
            }
        }

public function initMenu():void
{
//temp
viewComponent.clrPicker.addEventListener(ColorPickerEvent.CHANGE, onChangeColor);

categoriesDataProxy.loadMenuCategories();
}

private function buildMenuItems():void
{
var oldMenuItem:DisplayObject;
while(oldMenuItem = menu.getChildByName("MenuItem")){ menu.removeChild(oldMenuItem); }
menuItemCount = 0;

var data:Object = new Object();
data.ContentMC = ContentHomeMC;
buildMenuItem("MEMBERS",ApplicationFacade.LOAD_CONTENT, data);

var menuCategories:XMLList = categoriesDataProxy.categories;
for(var i:int = 0; i < menuCategories.length(); i++)
{
buildMenuItem(menuCategories[i].name,ApplicationFacade.LOAD_CATEGORY,{'ContentMC':ContentCategoryMC,'categoryID':menuCategories[i].@categoryID});
}

buildMenuItem("LEGSPERTS",ApplicationFacade.LOAD_CONTENT,{'ContentMC':ContentHomeMC});
buildMenuItem("NEWS",ApplicationFacade.LOAD_CONTENT,{'ContentMC':ContentHomeMC});
buildMenuItem("THE STORY",ApplicationFacade.LOAD_CONTENT,{'ContentMC':ContentHomeMC})
buildMenuItem("HOME",ApplicationFacade.LOAD_CONTENT,{'ContentMC':ContentHomeMC});
}

private function buildMenuItem(text:String,notification:String,data:Object):MenuItemMC
{
var format:TextFormat = new TextFormat();
            format.font = "VAGRounded LT Bold";
            format.color = 0xBEBEBE;
format.letterSpacing=1;
            format.size = 10;

var menuItemMC:MenuItemMC = new MenuItemMC();
menuItemMC.itemLabel.autoSize = TextFieldAutoSize.LEFT;
menuItemMC.name = "MenuItem";
menuItemMC.itemLabel.text = text.toUpperCase();

menu.addChild(menuItemMC);
menuItemMC.itemLabel.setTextFormat(format);
positionMenuItem(menuItemMC);
menuItemMC.button.btnBitmap.addEventListener(MouseEvent.MOUSE_UP,function()
{
sendNotification(notification,data);
});

return menuItemMC;
}

private function positionMenuItem(menuItemMC:MenuItemMC):void
{
menuItemCount++;

menuItemMC.y = TOP_PADDING + ((menuItemMC.height+5) * menuItemCount);
menuItemMC.x = (menu.width/2) - (menuItemMC.width/2);
menuItemMC.button.x = (menuItemMC.width/2) - (menuItemMC.button.width/2);
}

private function onChangeColor(event:ColorPickerEvent):void
{
trace("Change Color: "+ event.color)
var stageMediator:StageMediator = facade.retrieveMediator(StageMediator.NAME) as StageMediator;
StageMediator.BG_COLOR = event.color;
stageMediator.setBgColor();
}
    }
}
47  Announcements and General Discussion / Architecture / Re: sendNotification EventListener Bug on: January 21, 2008, 06:16:36
Why would it not work? The notification is dispatched and received that is not the problem. In my first post i mentioned that i also used a normal function instead of  the inline one above and it made no difference.
48  Announcements and General Discussion / Architecture / Re: sendNotification EventListener Bug on: January 21, 2008, 05:57:00
:
private function
buildMenuItem(text:String,notification:String,data:Object):MenuItemMC
{
var format:TextFormat = new TextFormat();
            format.font = "VAGRounded LT Bold";
            format.color = 0xBEBEBE;
format.letterSpacing=1;
            format.size = 10;

var menuItemMC:MenuItemMC = new MenuItemMC();
menuItemMC.itemLabel.autoSize = TextFieldAutoSize.LEFT;
menuItemMC.name = "MenuItem";
menuItemMC.itemLabel.text = text.toUpperCase();

menu.addChild(menuItemMC);
menuItemMC.itemLabel.setTextFormat(format);
positionMenuItem(menuItemMC);
menuItemMC.button.btnBitmap.addEventListener(MouseEvent.MOUSE_UP,function()
{
sendNotification(notification,data);
});

return menuItemMC;
}
49  Announcements and General Discussion / Architecture / Re: sendNotification EventListener Bug on: January 21, 2008, 05:53:14
That is exactly whats happening.

The view component in the Library dispatches an event, the mediator picks it up and dispatches a notification.

The StageMediator picks up that notification and places a child on into the display list.

The code i posted was taken from the mediator, not from the movieclip.
50  Announcements and General Discussion / Architecture / sendNotification EventListener Bug on: January 21, 2008, 05:26:38
Hello,

When using the following syntax there appears to be a problem.

var notification:String = "notificationString"
var data:Object = {'myVar':10}
menuItemMC.btnBitmap.addEventListener(MouseEvent.MOUSE_UP,function()
{
    sendNotification(notification,data);
});

When this notification is caught i add a child to the display list. The actionscript inside that child is ignored.

If i simply send the notification outside of the addEventListener everything works as expected.

There appears to be a bug in adding children to the display list from the onNotification method when the notification was dispatched from a native flash event.

I have also tried to define the function instead of typing it inline and the problem still occurs.

Pages: 1 2 3 [4]