A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS3 and XML image positioning

  1. #1
    Senior Member
    Join Date
    Jul 2009
    Posts
    167

    AS3 and XML image positioning

    Hi all

    I have been trying to make changes within some AS3 script that reads in XML images. I have a rotating menu that reads in images from xml. I can't seem to make the radius, the circle larger so the images are more spread out.

    with the images now being control by thye xml do I need add something to the xml ?

    many thanks for any help

    here is the actionscript;


    package
    {
    import flash.display.DisplayObject;
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
    import soulwire.ui.CircleMenu;
    public class Main extends Sprite
    {

    //__________________________________________________ _________ _____
    //覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧 CLASS MEMBERS VALUE

    public var circleMenu: CircleMenu;
    public var xmlLoader: URLLoader;

    //__________________________________________________ _________
    //覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧 CONSTRUCTOR

    public function Main()
    {
    circleMenu = new CircleMenu( 300, 32, 14 );
    circleMenu.x = 50;
    circleMenu.y = 300;
    addChildAt( circleMenu, 0 );

    // Use URLLoader to load XML

    xmlLoader = new URLLoader();
    xmlLoader.dataFormat = URLLoaderDataFormat.TEXT;

    // Listen for the complete event
    xmlLoader.addEventListener(Event.COMPLETE, onXMLComplete);
    xmlLoader.load(new URLRequest("data.xml"));


    /*for (var i:int = 0; i < 20; i++)
    {
    // MyMenuItem can be a symbol from your library
    // or any class which extends DisplayObject!

    var item:MyMenuItem = new MyMenuItem();

    item.txt.text = 'Menu Item ' + (i + 1);
    item.txt.mouseEnabled = false;
    item.buttonMode = true;
    item.addEventListener( MouseEvent.CLICK, onMenuItemClick );

    circleMenu.addChild( item );
    }

    circleMenu.currentIndex = 4;*/

    // Enable the mouse wheel

    stage.addEventListener( MouseEvent.MOUSE_WHEEL, onMouseWheel );

    // Set up the UI

    ui.spacingSlider.addEventListener( Event.CHANGE, onSliderChange );
    ui.radiusSlider.addEventListener( Event.CHANGE, onSliderChange );
    ui.minAlphaSlider.addEventListener( Event.CHANGE, onSliderChange );
    ui.minScaleSlider.addEventListener( Event.CHANGE, onSliderChange );
    ui.scaleSlider.addEventListener( Event.CHANGE, onSliderChange );
    ui.itemsSlider.addEventListener( Event.CHANGE, onSliderChange );

    ui.spacingSlider.dispatchEvent( new Event( Event.CHANGE) );
    ui.radiusSlider.dispatchEvent( new Event( Event.CHANGE) );
    ui.minAlphaSlider.dispatchEvent( new Event( Event.CHANGE) );
    ui.minScaleSlider.dispatchEvent( new Event( Event.CHANGE) );
    ui.scaleSlider.dispatchEvent( new Event( Event.CHANGE) );
    ui.itemsSlider.dispatchEvent( new Event( Event.CHANGE) );
    }

    //__________________________________________________ _________
    //覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧 EVENT HANDLERS

    private function onXMLComplete(event:Event):void
    {
    // Create an XML Object from loaded data
    var data:XML = new XML(xmlLoader.data);

    // Now we can parse it
    var images:XMLList = data.image;

    for(var i:int = 0; i < images.length(); i++)
    {
    // Get info from XML node
    var imageName:String = images[i].@name;
    var imagePath:String = images[i].@path;

    // Load images using standard Loader
    var loader:Loader = new Loader();

    // Listen for complete so we can center the image
    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,onImageComplete);
    loader.load(new URLRequest(imagePath));

    // Create a container for the loader (image)
    var holder:Sprite = new Sprite();
    holder.addChild(loader);

    // Same proceedure as before
    holder.buttonMode = true;
    holder.addEventListener( MouseEvent.CLICK, onMenuItemClick );

    // Add it to the menu
    circleMenu.addChild(holder);
    }
    }

    private function onImageComplete(event:Event):void
    {
    var img:Loader = event.currentTarget.loader;
    img.content["smoothing"] = true;
    img.x = -(img.width/2);
    img.y = -(img.height/2);
    }

    private function onMouseWheel( event:MouseEvent ):void
    {
    event.delta < 0 ? circleMenu.next() : circleMenu.prev();
    }

    private function onMenuItemClick( event:MouseEvent ):void
    {
    circleMenu.scrollToItem( event.currentTarget as DisplayObject );
    }

    private function onSliderChange( event:Event ):void
    {
    switch( event.currentTarget )
    {
    case ui.spacingSlider:
    circleMenu.angleSpacing = event.currentTarget.value;
    break;

    case ui.radiusSlider:
    circleMenu.innerRadius = event.currentTarget.value;
    break;

    case ui.minAlphaSlider:
    circleMenu.minVisibleAlpha = event.currentTarget.value;
    break;

    case ui.minScaleSlider:
    circleMenu.minVisibleScale = event.currentTarget.value;
    break;

    case ui.scaleSlider:
    circleMenu.activeItemScale = event.currentTarget.value;
    break;

    case ui.itemsSlider:
    circleMenu.visibleItems = event.currentTarget.value;
    break;
    }
    }

    }

    }

  2. #2
    World Kit Vote Holder Abelius's Avatar
    Join Date
    Feb 2002
    Location
    US
    Posts
    963
    Ummm... where do you find that soulwire thing???
    Cordially,
    Abelius
    www.worldkit.com

  3. #3
    Bald By Choice jasondefra's Avatar
    Join Date
    Mar 2008
    Location
    Wisconsin, USA
    Posts
    205
    Donkeykong, the best way to not get help on here is to paste an entire class package and ask someone to shuffle through it all to find where you need to make your change... not putting the class inside of Code/PHP tags just adds insult to injury. Also, if you're using someone else's work it would help to let us know what it is you're using so we have a better understanding of what's going on before looking at it. Hopefully you're not plagiarizing somebody else's non-opensource Actionscript...

    With that said, I think if you play around with the values on this line of code you may be able to increase your radius:
    PHP Code:
    circleMenu = new CircleMenu3003214 ); 
    Last edited by jasondefra; 07-13-2009 at 05:34 PM.
    Follow me on Twitter: http://twitter.com/jasondefra

  4. #4
    Senior Member
    Join Date
    Jul 2009
    Posts
    167
    Hi guys

    thanks for the reply back!

    Abelius
    I got the script from jason at soulwire, the link is here: http://blog.soulwire.co.uk/flash/act...circular-menu/

    JasonDefra
    I apologise if I have up set people, that was never my intention, I am new to this so just trying to get help! Not putting the class inside of code/php tags, what is this, sorry again I do not understand, I apologise!

    I am not plagiarizing anyones work I downloaded shareware files from soulwire(see above link) I have also been in touch via email with jason at soulwire who has sent me some more files, and I am awating another reply regarding same issues, i just didn't want to pester him to much. so I am trying to get help from people who don't find helping newbies and basically trying to understand it and do it myself!

    Yes I have tried playing around with thoughs values but they do not work now, as the xml is driving the images.

    I have uploaded the working files to somespace you can download as the files are to big for flashkit, see here: http://art.clubworldgroup.com/menu.zip

    once again, I apologise if I upset people, that was never my intention. If you think you could help I would be very greatfull.

    thank you for your time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center