Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

creating menu from xml

Participant ,
Apr 26, 2013 Apr 26, 2013

Hi, I found a script from developphp.com, what it does is to make a button menu with elements from a external xml file. the fla has nothing no stage besides as3 script. It creates a 'rect' with as3 and then load the 'text' and 'link' into it from xml file.

What I want to change is instead of creating the 'rect', it input an image from the xml file, and turn it to a button the same way like how the 'rect' was like.

This is the as3 script, it's working.

Thank yo for helping

TOPICS
ActionScript
882
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Apr 26, 2013 Apr 26, 2013

problem solved, .. I change the 'e.target.ccc' to 'e.currentTarget.ccc', i still don't understand why target.ccc work for original but not mine, but the buttons work now.

function clipClick(e:Event):void {

                    trace(e.target.ccc);       

                      var targetURL:String = e.currentTarget.ccc;  << -- change from 'e.target.ccc' to 'e.currentTarget.ccc'

                      var urlRequest:URLRequest = new URLRequest(targetURL);

                      navigateToURL(urlRequest);

...
Translate
Participant ,
Apr 26, 2013 Apr 26, 2013

var yPlacement:int = 10;

var xPlacement:int = 50;

var distance:int = 32;

var format:TextFormat = new TextFormat();

format.color = 0x000000;

format.font = "Verdana";

format.size = 11;

format.kerning = false;

var myXML:XML = new XML();

var XML_URL:String = "XML_driven_menu1.xml";

var myXMLURL:URLRequest = new URLRequest(XML_URL);

var myLoader:URLLoader = new URLLoader(myXMLURL);

myLoader.addEventListener("complete", xmlLoaded);

function xmlLoaded(event:Event):void {

   

  

    myXML = XML(myLoader.data);

  

    var xmlDoc:XMLDocument = new XMLDocument();

   

    xmlDoc.ignoreWhite = true;

   

    var menuXML:XML = XML(myLoader.data);

   

    xmlDoc.parseXML(menuXML.toXMLString());

   

  

    var i:Number = 0;

  

    for each (var MenuItem:XML in myXML..MenuItem) {

   

   

    var listLabel:String = MenuItem.itemLabel.toString();

  

    var listurl:String = MenuItem.urlstring.toString();

                              var type:String = GradientType.LINEAR;

                             var colors:Array = [0xFFFFFF, 0xCCCCCC];

                             var alphas:Array = [1, 1];

                             var ratios:Array = [0, 255];

                             var spreadMethod:String = SpreadMethod.PAD;

                             var interp:String = InterpolationMethod.LINEAR_RGB;

                             var focalPtRatio:Number = 0;

                             var matrix:Matrix = new Matrix();

                             var boxWidth:Number = 100;

                             var boxHeight:Number = 20;

                             var boxRotation:Number = Math.PI/2; // 90Ëš

                             var tx:Number = 0;

                             var ty:Number = 0;

                             matrix.createGradientBox(boxWidth, boxHeight, boxRotation, tx, ty);

                             var rect:Shape = new Shape;

                             rect.graphics.beginGradientFill(type, colors, alphas, ratios, matrix, spreadMethod, interp, focalPtRatio);

                             rect.graphics.lineStyle(1, 0x999999);

                             rect.graphics.drawRect(0, 0, 100, 20);

                            

                            

                             var myText:TextField = new TextField();

                               myText.autoSize = TextFieldAutoSize.LEFT;

                             myText.antiAliasType = AntiAliasType.ADVANCED;

                             myText.defaultTextFormat = format;

                             myText.selectable = false;

                             myText.mouseEnabled = false;

                             myText.text = listLabel;

                             myText.x = 2;

                             myText.y = 2;

                             addChild(myText);

                              var clip_mc = new MovieClip();

                                

                             clip_mc.addChild(rect);

                                

                             clip_mc.addChild(myText);

                                

                             addChild(clip_mc);

                                

                             clip_mc.buttonMode = true;           

                              yPlacement = yPlacement + 28;

                                

                             clip_mc.y = yPlacement;

                                

                             clip_mc.x = xPlacement;          

                            

                                

                             clip_mc.clickToPage = listurl;

                               

                             clip_mc.addEventListener (MouseEvent.CLICK, clipClick);

                                

                             clip_mc.addEventListener (MouseEvent.MOUSE_OVER, onMouseOver);

                             clip_mc.addEventListener (MouseEvent.MOUSE_OUT, onMouseOut);

                            

                               

                             function clipClick(e:Event):void {

                                var targetURL:String = e.target.clickToPage;

                                var urlRequest:URLRequest = new URLRequest(targetURL);

                                navigateToURL(urlRequest);

                             }

                             i++;

            

}

   

   

}

    

function onMouseOver (e:Event):void {

   

    

     var bevel:BevelFilter = new BevelFilter();

     bevel.distance = 1;

     bevel.angle = 45;

     bevel.shadowColor = 0x666666;

     bevel.shadowAlpha = 0.5;

     bevel.strength = 4;

     bevel.quality = BitmapFilterQuality.MEDIUM;

     bevel.type = BitmapFilterType.INNER;

     bevel.knockout = false;

     var glow:GlowFilter = new GlowFilter();

     glow.color = 0x79B3E1;

     glow.alpha = 1;

     glow.quality = BitmapFilterQuality.MEDIUM;

    

     var filtersArray:Array = new Array(bevel, glow);

    

     e.target.filters = filtersArray;

}

    

function onMouseOut (e:Event):void {

   

        

    e.target.filters = null;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 26, 2013 Apr 26, 2013

I modified the code, this is what I got so far, and this is where I got stuck, it gave me error:

"ReferenceError: Error #1069: 在 flash.display.Loader cannot find ccc,no value

    at MethodInfo-4()."

but then I traced 'ccc' and it shows the correct the links that I have on xml.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 26, 2013 Apr 26, 2013

stop();

var yPlacement:int = 20;

var xPlacement:int = 30;

var distance:int = 175;

var myXML:XML = new XML();

var XML_URL:String = "xmlphonemod.xml";

var myXMLURL:URLRequest = new URLRequest(XML_URL);

var myLoader:URLLoader = new URLLoader(myXMLURL);

myLoader.addEventListener("complete",xmlLoaded);

function xmlLoaded(event:Event):void {

   

    myXML = XML(myLoader.data);

   

    var xmlDoc:XMLDocument = new XMLDocument();

   

    xmlDoc.ignoreWhite = true;

   

    var menuXML:XML = XML(myLoader.data);

   

    xmlDoc.parseXML(menuXML.toXMLString());

   

        for each (var Listitem:XML in myXML..ListItem) {

            var listImage:String = Listitem.itemImage.toString();

            var listLabel:String = Listitem.itemLabel.toString();

            var listPhone:String = Listitem.itemPhone.toString();

           

                        var myText1:TextField = new TextField();

            myText1.text = listLabel;

            myText1.autoSize = TextFieldAutoSize.LEFT;

            myText1.x = 2;

            myText1.y = 2;

                       

            var myText2:TextField = new TextField();

            myText2.text = listPhone;

            myText2.autoSize = TextFieldAutoSize.LEFT;

            myText2.x = 2;

            myText2.y = 20;

           

            //-----------------------------

            var myImage:TextField = new TextField();

            var fileRequest:URLRequest = new URLRequest(listImage);

            var newLoader:Loader = new Loader()

            newLoader.load(fileRequest);

            //myImage.text = listImage;

            //myImage.autoSize = TextFieldAutoSize.LEFT;

           

            newLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);

            newLoader.x = 2;

            newLoader.y = 0;

           

            function onLoaderReady(e:Event) {    

              var myBitmapData:BitmapData = new BitmapData(newLoader.width, newLoader.height);

               myBitmapData.draw(newLoader);

               var myBitmap:Bitmap = new Bitmap;

               myBitmap.bitmapData = myBitmapData;

               //addChild(myBitmap);

           

            }

            var clip_mc = new MovieClip();

           

            clip_mc.addChild(newLoader);

            clip_mc.addChild(myText1);

            clip_mc.addChild(myText2);

           

            addChild(clip_mc);

            yPlacement = yPlacement + distance;

            clip_mc.buttonMode = true;   

            clip_mc.y = yPlacement;

            clip_mc.x = xPlacement;

           

            trace (listPhone);

           

            clip_mc.ccc = listPhone;

            trace (clip_mc.ccc);

           

            clip_mc.addEventListener(MouseEvent.CLICK, clipClick);

            clip_mc.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);

            clip_mc.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);

           

           

            function clipClick(e:Event):void {

                    trace(e.target.ccc);       

                      var targetURL:String = e.target.ccc;

                      var urlRequest:URLRequest = new URLRequest(targetURL);

                      navigateToURL(urlRequest);

             }

        }

       

       

        function onMouseOver (e:Event):void {

   

            // Create the filters and add them to an array

                var bevel:BevelFilter = new BevelFilter();

                bevel.distance = 1;

                bevel.angle = 45;

                bevel.shadowColor = 0x666666;

                bevel.shadowAlpha = 0.5;

                bevel.strength = 4;

                bevel.quality = BitmapFilterQuality.MEDIUM;

                bevel.type = BitmapFilterType.OUTER;

                bevel.knockout = false;

                var glow:GlowFilter = new GlowFilter();

                glow.color = 0x79B3E1;

                glow.alpha = 1;

                glow.quality = BitmapFilterQuality.MEDIUM;

            // Pack the filter paramters into the array variable

                var filtersArray:Array = new Array(bevel, glow);

            // Assign the filters array to the display object to apply the filter

                e.target.filters = filtersArray;

        }

        // Set the mouse out function for all movieclip buttons

        function onMouseOut (e:Event):void {

   

        // Remove the Filters on Mouse Out

            e.target.filters = null;

        }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 26, 2013 Apr 26, 2013

function clipClick(e:Event):void {

                    trace(e.target.ccc);       

                      var targetURL:String = e.target.ccc;  << -- no value

                      var urlRequest:URLRequest = new URLRequest(targetURL);

                      navigateToURL(urlRequest);

             }

after I tested several traces problem is in this function, I don't understand why e.target.ccc has no value in my function while it work properly in the original script.  It's copy from the original script, I just changed 'clickToPage' to 'ccc'. but mine doesn't work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 26, 2013 Apr 26, 2013

I think i forgot to mention my script does run and images work as button just fine, but when I click them it gave that error

"ReferenceError: Error #1069: 在 flash.display.Loader cannot find ccc,no value

    at MethodInfo-4()."

I checked line by line with the original script for hours I don't find what original script has that I don't cause the difference.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 26, 2013 Apr 26, 2013
LATEST

problem solved, .. I change the 'e.target.ccc' to 'e.currentTarget.ccc', i still don't understand why target.ccc work for original but not mine, but the buttons work now.

function clipClick(e:Event):void {

                    trace(e.target.ccc);       

                      var targetURL:String = e.currentTarget.ccc;  << -- change from 'e.target.ccc' to 'e.currentTarget.ccc'

                      var urlRequest:URLRequest = new URLRequest(targetURL);

                      navigateToURL(urlRequest);

             }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines