Announcement Announcement Module
Collapse
No announcement yet.
Referencing items in flash. warning long post. Page Title Module
Move Remove Collapse
Search Search Module
Collapse

Advertisement Advertisement Module
Collapse

Featured Images Featured Images Module
Collapse

Mediabistro Creative Sites Mediabistro Creative Sites Module
Collapse
Latest Topics Latest Topics Module
Collapse

Advertisement Advertisement Module
Collapse

Sponsors Sponsors Module
Collapse

X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Referencing items in flash. warning long post.

    Hello again. im making a website to showcase my portfolio, and so far it's going ok. There are some things that I need help with, technical issues because I'm just learning to use flash properly. If you can help thanks sooo much, otherwise just check back on the site periodically and give me feed back. I'll post the Action Script and the XML i have, for reference. I know you are all primarily print designers, but if there is a web guru in here that'd be great! Again, it's a long list of stuff, all of which I'm trying to make happen, if you can help out with one great, multiple items splendid.

    my site is at www.esteban-sandoval.com

    what I would like to do is:

    1. Find out how to place my flash animation in the middle of the browser window, not matter how big or small it gets.
    2. How to determine the size of the browser window when it opens.
    3. How to specify a minimum width and height of the browser window.
    a good example of what I would like to achieve is at www.killthepixelnow.com after entering the site.
    4. In terms of modifying my site: how to get the menu bars to have different colors/patterns.
    5. how to change the colors of the fonts in the menu bars.

    #4 is hard for me because the way I have the coding set up is that I have a movie clip in flash that is referenced upon every occurrence of its name in action script. It's the same image/clip with a dynamic text box in order to change the title for the different instances its used in. The dynamic text thing is the same, if I change the color in flash it will be changed for all 4 bars, but I would like them to each be different colors (cmyk probably).
    actionscript:
    //import tweenlite classes
    import gs.TweenLite;
    import gs.easing.*;

    var MENU_ARRAY:Array; //used to save the items data
    var OPENED_MENU:int; //to inform the menu that should be open at startup
    var MOVE_ON_MOUSE_OVER:Boolean=false; //tha name says everything
    var xmlLoader:URLLoader; //the xml loader

    loadXML("menu.xml"); //load the xml

    function loadXML(Uri:String):void {
    xmlLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, onComplete);
    xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);
    xmlLoader.load(new URLRequest(Uri));
    }

    function onError(evt:ErrorEvent):void {
    trace("cannot load xml file");
    }

    function onComplete(evt:Event):void {
    //read and load xml into array, by parsing it using prepareMenu
    MENU_ARRAY=prepareMenu(xmlLoader.data.toString());
    placeItemsOnStage(); //place all required items on stage.
    }

    function placeItemsOnStage():void {
    var pos:Number=0;
    //define the container properties
    menuContainer.x=0;
    menuContainer.y=0;

    for(var c:int=0; c<MENU_ARRAY.length; c++) {
    var it:menuItem = new menuItem; //load out menuItem, because its exported to AS, we can use it here
    it.x=c*25; //its the gray border width
    it.y=0; //place on top
    it.id="Item-"+c; //id the menuItem
    it.name="Item-"+c; //name de menuItem
    it.posX=pos; //actual pos, useful to open and know is position
    it.itemLabel.text=String(MENU_ARRAY[c].Ititle).toUpperCase(); //load the label in uppercase
    it.addEventListener(MouseEvent.CLICK, onMouseClick); //add mouse click listener
    if(MOVE_ON_MOUSE_OVER==true) it.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); //if configured, load the mouse over event
    it.useHandCursor=false; //use hand cursor
    it.buttonMode=true; //buttonMode
    it.itemText.visible=false; //hide the textField
    menuContainer.addChild(it); //add the menu item as child

    if(String(MENU_ARRAY[c].IcontentType)=="image/swf") { //check the content and load things accordint to it
    var ldr:Loader = new Loader();
    ldr.x=25;
    ldr.y=0;
    it.addChild(ldr);
    ldr.load(new URLRequest(MENU_ARRAY[c].IcontentData.toString()));
    }
    else if(String(MENU_ARRAY[c].IcontentType)=="text") {
    it.itemText.visible=true;
    it.itemText.text=MENU_ARRAY[c].IcontentData.toString();
    }
    pos+=25; //the next menuItem x position
    }

    //put mask in place
    masker.width=(MENU_ARRAY.length*1024)
    masker.height=menuContainer.height;
    masker.x=0;
    masker.y=0;

    moveItem(OPENED_MENU-1); //open menu confirured in XML

    }

    function onMouseOver(evt:MouseEvent):void {
    if(evt.target.name.toString()=="buttonBack") prepareMove(evt)
    }

    function prepareMove(evt:MouseEvent):void {
    var targetName:String = evt.currentTarget.name.toString(); //get the menuItem
    var temp:Array = targetName.split("-"); //split his name: Item-x
    var itemNumber:int=(temp[1]); //got item number
    moveItem(itemNumber); //move it
    }

    function onMouseClick(evt:MouseEvent):void {
    if(evt.target.name.toString()=="buttonBack") prepareMove(evt); //mouse action was done in buttonBack
    else trace("Item "+evt.currentTarget.name+" clicked!"); //mouse action was made on accordion area
    }

    function moveItem(num:int):void {
    var itemToMove:menuItem=menuContainer.getChildByName(" Item-"+String(num)) as menuItem;
    //get the menuItem child
    for(var m=0;m<MENU_ARRAY.length;m++) //move one-by-one to the new position
    {
    var tempMc = menuContainer.getChildByName("Item-"+m);
    if(tempMc.x > itemToMove.x) TweenLite.to(tempMc, 1, {x(tempMc.posX) + itemToMove.width-138), ease:Quart.easeOut}); //see tweenLite for info about this.
    else if(tempMc.x <= itemToMove.x) TweenLite.to(tempMc, 1, {xtempMc.posX), ease:Quart.easeOut});
    }
    }

    function prepareMenu (XMLData:String):Array
    {
    //make sure it cames in XML
    var menuXML:XML = new XML(XMLData);
    //just in case
    menuXML.ignoreWhitespace = true;

    //get XML item's entrys
    var XMLItems = menuXML.descendants("item");

    //load all items into an array
    var itemsArray:Array = new Array();
    var itemObj:Object;
    for(var i in XMLItems)
    {
    itemObj=new Object();
    itemObj.Ititle=XMLItems[i].@Ititle;
    itemObj.IcontentType=XMLItems[i].@IcontentType;
    itemObj.IcontentData=XMLItems[i].@IcontentData;
    itemObj.itemID="menu"+i;
    itemsArray.push(itemObj);
    }
    OPENED_MENU=menuXML.@menuOpen; //get menu for open.
    MOVE_ON_MOUSE_OVER=(menuXML.@moveOnMouseOver.toStr ing()=="true" ? true : false); //get the option for load or not mouseOver open
    return itemsArray;
    }

    //finish.
    stop();

    xml:
    here is the action script and xml. if you would like me to post the html file that flash publishes just let me know.
    <?xml version="1.0" encoding="utf-8"?>
    <menu menuOpen="1" moveOnMouseOver="false">

    <item Ititle="Home" IcontentType="text" IcontentData="Hello and welcome to my website. As you can see, it is currently under construction, but is scheduled to be completed by May '10. Please visit again to see changes and updates."/>

    <item Ititle="PORTFOLIO" IcontentType="text" IcontentData="Custom Text"/>

    <item Ititle="PHOTOGRAPHY" IcontentType="image/swf" IcontentData="space_gallery.swf"/>

    <item Ititle="RESUME" IcontentType="image/swf" IcontentData="image4.jpg"/>

    <item Ititle="CONTACT" IcontentType="image/swf" IcontentData="image2.jpg"/>





    </menu>



    Thanks for looking at this guys, i know it can be a pretty daunting task to deal with coding.
Mediabistro A division of Prometheus Global Media home | site map | advertising/sponsorships | careers | contact us | help courses | browse jobs | freelancers | content | member benefits | reprints & permissions terms of use | privacy policy Copyright © 2014 Mediabistro Inc.
Working...
X