Menu

Is there a workaround if you don't have Flex?

Flare Help
2009-03-02
2013-05-29
  • Nathaniel Whitcomb

    Can I use Flare with the authoring tools in Flash alone or is Flex an absolute necessity?

     
    • Carlos Carvalhar

      yeah you can use only flash.

      i did a example in flash to see if it's possible or no, but i thougth it's a bit boring to work in flash, because coding in flex is easier.

      the process in flash is simple, just add the classes trougth import.

      ps: you can use flex for coding the flash AS files:
      http://onflash.org/ted/2007/08/using-flex-builder-for-flash-cs3-code.php

       
    • Nathaniel Whitcomb

      But there are references to components only available through flex... like mx.core.IMXMLObject  and a few others. I keep getting errors when trying to test the swf from flash. Any thoughts on how to get around this?

       
      • Carlos Carvalhar

        well, in flash you don't need flare vis...and if there's a need to import other classes from flex, try to search for the as file over google, to downlaod it.

        i got a flare code at internet from someone, i can't remember who, and made it in flash code just to test if flare works in flash.

        here it is...
        import flare.animate.Transitioner;
        import flare.data.DataSet;
        import flare.display.RectSprite;
        import flare.display.TextSprite;
        import flare.vis.Visualization;
        import flare.vis.data.Data;
        import flare.vis.data.NodeSprite;
        import flare.vis.operator.filter.GraphDistanceFilter;
        import flare.vis.operator.layout.RadialTreeLayout;
        import flash.display.MovieClip;
        import flash.display.Loader;
        import flash.display.Sprite;
        import flash.events.MouseEvent;
        import flash.geom.Rectangle;
        import flash.net.URLRequest;
        import flash.text.TextFormat;

        //import panda;

        var vis:Visualization;

        var maxLabelWidth:Number;
        var maxLabelHeight:Number;

        var _gdf:GraphDistanceFilter;

        var _maxDistance:int = 2;

        var _transitionDuration:Number = 2;

        function GraphMLFileDemo() {
            var gmr:GraphMLReader = new GraphMLReader(onLoaded);
            gmr.read("janetyc_graphml.xml");
        }
        function onLoaded(data:Data):void {

            vis = new Visualization(data);

            var w:Number = stage.stageWidth;
            var h:Number = stage.stageHeight;

            vis.bounds = new Rectangle(0, 0, w, h);

            var textFormat:TextFormat = new TextFormat();
            textFormat.color = 0xffffffff;
            var i:int = 0;
            vis.data.nodes.visit(function(ns:NodeSprite):void {
            var ts:TextSprite = new TextSprite(ns.data.tag,textFormat);
            ns.addChild(ts);
            });

            vis.data.nodes.setProperty("x",w/2);
            vis.data.nodes.setProperty("y",h/2);

            maxLabelWidth = getMaxTextLabelWidth();
            maxLabelHeight = getMaxTextLabelHeight();

            vis.data.nodes.visit(function(ns:NodeSprite):void {
            var rs:RectSprite = new RectSprite( -maxLabelWidth/2-1,-maxLabelHeight/2 - 1, maxLabelWidth + 2, maxLabelHeight + 2,5,5);
            if (ns.data.gender == "M") {
            rs.fillColor = 0xff000044;
            rs.lineColor = 0xff000044;
            } else {
            rs.fillColor = 0xffaa0000;
            rs.lineColor = 0xffaa0000;
            rs.alpha = 0.8;
           
            }
            rs.lineWidth = 2;
           
            ns.addChildAt(rs, 0); // at postion 0 so that the text label is drawn above the rectangular box
           
            /*// Add the image thumbnail to the children
            var loader:Loader = new Loader();
            //var url:String = "file.png";
            var url:String = "importado.swf";
            var urlReq:URLRequest = new URLRequest(url);
            loader.load(urlReq);
            loader.x = - 25;
            loader.y = - 5;
           
            rs.addChild(loader); */

            ns.addChildAt(new panda(),1);
            //rs.addChildAt(panda, 1);
               
            ns.size = 0;
            adjustLabel(ns,maxLabelWidth,maxLabelHeight);
           
            ns.mouseChildren = false;
           
            ns.addEventListener(MouseEvent.CLICK, update);
            ns.addEventListener(MouseEvent.ROLL_OVER, getNode);
            ns.buttonMode = true;
            });

            var lay:RadialTreeLayout =  new RadialTreeLayout();
            lay.useNodeSize = false;

            var root:NodeSprite = vis.data.nodes[0];

            _gdf = new GraphDistanceFilter([root], _maxDistance,NodeSprite.GRAPH_LINKS);

            vis.operators.add(_gdf);//distance filter has to be added before the layout
            vis.operators.add(lay);

            addChild(vis);

            updateRoot(root);

        }

        function getNode(event:MouseEvent):void {

            var n:NodeSprite = event.target as NodeSprite;
            if (n == null) {
                return;
            }
            //n.getChildAt(1).Oi();
            trace("n is " + n.name + "(" + n.x +","+ n.y+ ")");
            trace("n1  is " + n.getChildAt(1).name + "(" + n.x +","+ n.y+ ")");
            //instance30.scaleX = 899;
            //n.panda.RotateCircle();

        }

        function update(event:MouseEvent):void {

            var n:NodeSprite = event.target as NodeSprite;
            if (n == null) {
                return;
            }
            updateRoot(n);

        }
        function updateRoot(n:NodeSprite):void {

            vis.data.root = n;

            _gdf.focusNodes = [n];

            var t1:Transitioner = new Transitioner(_transitionDuration);

            vis.update(t1).play();

        }
        function getMaxTextLabelWidth():Number {
            var maxLabelWidth:Number = 0;
            vis.data.nodes.visit(function(n:NodeSprite):void {
            var w:Number = getTextLabelWidth(n);
            if (w > maxLabelWidth) {
            maxLabelWidth = w;
            }
           
            });
            return maxLabelWidth;
        }
        function getMaxTextLabelHeight():Number {
            var maxLabelHeight:Number = 0;
            vis.data.nodes.visit(function(n:NodeSprite):void {
            var h:Number = getTextLabelHeight(n);
            if (h > maxLabelHeight) {
            maxLabelHeight = h;
            }
           
            });
            return maxLabelHeight;
        }
        function getTextLabelWidth(s:NodeSprite):Number {
            var s2:TextSprite = s.getChildAt(s.numChildren-1) as TextSprite;// get the text sprite belonging to this node sprite
            var b:Rectangle = s2.getBounds(s);
            return s2.width;
        }
        function getTextLabelHeight(s:NodeSprite):Number {
            var s2:TextSprite = s.getChildAt(s.numChildren-1) as TextSprite;// get the text sprite belonging to this node sprite
            var b:Rectangle = s2.getBounds(s);
            return s2.height;
        }
        function adjustLabel(s:NodeSprite, w:Number, h:Number):void {

            var s2:TextSprite = s.getChildAt(s.numChildren-1) as TextSprite;// get the text sprite belonging to this node sprite

            s2.horizontalAnchor = TextSprite.CENTER;
            s2.verticalAnchor = TextSprite.CENTER;

        }

        GraphMLFileDemo();

         
    • Nathaniel Whitcomb

      Carlos,
      I tried running your script and I got the same error as when trying my own.
      Description: 1045: Interface IMXMLObject was not found.

       
      • Carlos Carvalhar

        yeah, that's boring.. but easy:
        you need to place IMXMLObject.as inside a directory mx/core at the same level of your fla.

        eg:
        /my.fla
        /mx/core/IMXMLObject.as

        as i've said before, if there's a need to import other classes from flex, try to search for the as file over google.
        dont forget to place it at the rigth package.

        IMXMLObject.as

        ////////////////////////////////////////////////////////////////////////////////
        //
        //  Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors.
        //  All Rights Reserved. The following is Source Code and is subject to all
        //  restrictions on such code as contained in the End User License Agreement
        //  accompanying this product.
        //
        ////////////////////////////////////////////////////////////////////////////////

        package mx.core
        {

        /**
        *  The IMXMLObject interface defines the APIs that a non-visual component
        *  must implement in order to work properly with the MXML compiler.
        *  Currently, the only supported method is the <code>initialized()</code>
        *  method.
        */
        public interface IMXMLObject
        {
            //--------------------------------------------------------------------------
            //
            //  Methods
            //
            //--------------------------------------------------------------------------

            /**
             *  Called after the implementing object has been created and all
             *  component properties specified on the MXML tag have been initialized.
             *
             *  @param document The MXML document that created this object.
             *
             *  @param id The identifier used by <code>document</code> to refer
             *  to this object.
             *  If the object is a deep property on <code>document</code>,
             *  <code>id</code> is null.
             */
            function initialized(document:Object, id:String):void;
        }

        }

         
    • Nathaniel Whitcomb

      Thanks! I go it working now!

       
  • bobhaslett

    bobhaslett - 2011-07-14

    I'd really like to be able to use flare in the flash environment for graphics but have struggled with the above. I am now getting the following erroe
    Scene 1, Layer 'Layer 1', Frame 1, Line 21 1172: Definition panda could not be found.
    Scene 1, Layer 'Layer 1', Frame 1, Line 21 1172: Definition panda could not be found.
    Scene 1, Layer 'Layer 1', Frame 1, Line 35 1046: Type was not found or was not a compile-time constant: GraphMLReader.
    Scene 1, Layer 'Layer 1', Frame 1, Line 35 1180: Call to a possibly undefined method GraphMLReader.
    Scene 1, Layer 'Layer 1', Frame 1, Line 90 1180: Call to a possibly undefined method panda.

    grateful for any help

     
  • Alec

    Alec - 2011-08-03

    hi bob,

    the panda definition cannot be found may be because you have to name the instance, not just the class.  so if you have a panda on the flash stage, click it, and under properties, give it an instance name of panda as well.

    as for the GraphMLReader problems, you shouldn't ever need to actually write GraphMLReader.  Flare is set up so you can simply make a call like this:

                var ds:DataSource = new DataSource(
                    "XMLNAME.xml", "graphml");
    

    the dataSource can then call the appropriate loader for a graphML, like this:

                var loader:URLLoader = ds.load();
                loader.addEventListener(Event.COMPLETE, function(evt:Event):void {
                    var ds:DataSet = loader.data as DataSet;
                    visualize(Data.fromDataSet(ds));
                });
    

    so in other words panda is undefined because you properly just need to define it and graphML is undefined because you should never need to use something called that.

     
  • bobhaslett

    bobhaslett - 2011-08-12

    Thanks very much for that. I seem to have got most of the flare package working in the Flash environment now, although struggling with some of the syntax as documentation is a bit scarce. REALLY have trouble with the force directed layout though. Whenever I make a call to it or indeed anything in the 'physics' library I get load of erors ( listed below). I'd appreciate any help anyone can give

    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 195 1119: Access of possibly undefined property p2 through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 194 1119: Access of possibly undefined property p1 through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 193 1119: Access of possibly undefined property p2 through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 193 1119: Access of possibly undefined property p1 through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 193 1119: Access of possibly undefined property die through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 155 1119: Access of possibly undefined property p2 through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 154 1119: Access of possibly undefined property p1 through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 116 1119: Access of possibly undefined property p2 through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 116 1119: Access of possibly undefined property p1 through a reference with static type Spring.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 315 1137: Incorrect number of arguments.  Expected no more than 0.
    /Users/bob.haslett/Documents/MF1/Pending/Phone hacking/flare/physics/Simulation.as, Line 312 1061: Call to a possibly undefined method init through a reference with static type Spring.

     

Log in to post a comment.