EasyCFM.COM ColdFusion Forums / Flex Development / A3 FLEX PROJECT

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: A3 FLEX PROJECT

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

zionist
07-10-2008 @ 6:05 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 94
Joined: Feb 2007

Hi guys i have been learning how to use AS3 and i started out with creating custom controls for a mapping application am working on. i succeded in creating the controls but the embedded images in the controls are blured maybe am missing something. please look at this code and advise. plus the conrols are part of a larger sprite and i would like them to move whereever the parent sprite is moved.

package {
     import flash.display.*;
     import flash.text.*;
     import flash.net.URLRequest;
     import mx.core.BitmapAsset;
     public class graphics extends Sprite
     {
          //[Embed(source="zoomin.png")]
        //public var imgcls:Class;
        //private var img:Bitmap = new imgcls();

          public function graphics()
          {
               var mySprite:Sprite = new Sprite();
               mySprite.x = 0;
             mySprite.y = 0;
             var label:TextField = new TextField();
               label.text = "DEPTH";
               label.x = 4;
               label.y = 2;
               label.textColor = 0xFFFFFF;
               label.height = 20;
            label.width = 35;
            label.wordWrap = true;
            var format:TextFormat = new TextFormat();
            format.size = 6;
               format.font = "Arial";
               format.bold = false;
              label.setTextFormat(format);
              var buttonWidth:Number = 60;
              var background:Shape = new Shape();
              background.graphics.beginFill(0x000000);
              background.graphics.drawRoundRect(0, 0, buttonWidth, 30, 15);
              background.alpha = .5;
              var loaderholder:Sprite = new Sprite();
              loaderholder.graphics.beginFill(0*000000);
              loaderholder.graphics.drawCircle(11, 20, 6);
              loaderholder.alpha = .5;
              var loaderholder1:Sprite = new Sprite();
              loaderholder1.graphics.beginFill(0*000000);
              loaderholder1.graphics.drawCircle(32, 20, 6);
              loaderholder1.alpha = .5;              
              var loader:Loader = new Loader();
                loader.x = 8.5;
               loader.y = 17.5;
               var url:URLRequest = new URLRequest("../zoomin.png");
               loader.load(url);
               var loader1:Loader = new Loader();
                loader1.x = 29.5;
               loader1.y = 19.5;
               var url1:URLRequest = new URLRequest("../zoomout.png");
               loader1.load(url1);
               loaderholder.addChild(loader);
               this.addChild(loaderholder);
               loaderholder1.addChild(loader1);
               this.addChild(loaderholder1);
              mySprite.addChild(background);
              mySprite.addChild(label);
              mySprite.addChild(loaderholder);
              mySprite.addChild(loaderholder1);              
              this.addChild(mySprite);
              //////navigation/////////////////////////////////////////////////////////////////////////////////////////
              var mySprite1:Sprite = new Sprite();
               mySprite1.x = 30;
             mySprite1.y = 15;             
              var navigator:Sprite = new Sprite();
              navigator.graphics.beginFill(0*000000);
              navigator.graphics.drawCircle(0, 50, 30);
              navigator.alpha = .5;
              var middleholder:Sprite = new Sprite();
              middleholder.graphics.beginFill(0*000000);
              middleholder.graphics.drawCircle(0, 50, 6);
              middleholder.alpha = .5;
              var middle:Loader = new Loader();
                middle.x = -2.5;
               middle.y = 48;
               var middle_url:URLRequest = new URLRequest("../middle.png");
               middle.load(middle_url);
               middleholder.addChild(middle);
              this.addChild(middleholder);
              var northholder:Sprite = new Sprite();
              northholder.graphics.beginFill(0*000000);
              northholder.graphics.drawCircle(0, 30, 6);
              northholder.alpha = .5;
              var north:Loader = new Loader();
                north.x = -2.5;
               north.y = 27;
               var north_url:URLRequest = new URLRequest("../north_triangle.png");
               north.load(north_url);
               northholder.addChild(north);
              this.addChild(northholder);
              var southholder:Sprite = new Sprite();
              southholder.graphics.beginFill(0*000000);
              southholder.graphics.drawCircle(0, 70, 6);
              southholder.alpha = .5;
              var south:Loader = new Loader();
                south.x = -2.5;
               south.y = 67;
               var south_url:URLRequest = new URLRequest("../south_triangle.png");
               south.load(south_url);
               southholder.addChild(south);
              this.addChild(southholder);
              var eastholder:Sprite = new Sprite();
              eastholder.graphics.beginFill(0*000000);
              eastholder.graphics.drawCircle(20, 50, 6);
              eastholder.alpha = .5;
              var east:Loader = new Loader();
                east.x = 19;
               east.y = 47;
               var east_url:URLRequest = new URLRequest("../east_triangle.png");
               east.load(east_url);
               eastholder.addChild(east);
              this.addChild(eastholder);
              var westholder:Sprite = new Sprite();
              westholder.graphics.beginFill(0*000000);
              westholder.graphics.drawCircle(-20, 50, 6);
              westholder.alpha = .5;
              var west:Loader = new Loader();
                west.x = -23;
               west.y = 47;
               var west_url:URLRequest = new URLRequest("../west_triangle.png");
               west.load(west_url);
               westholder.addChild(west);
              this.addChild(westholder);               
              mySprite1.addChild(navigator);
              mySprite1.addChild(middleholder);
              mySprite1.addChild(northholder);
              mySprite1.addChild(southholder);
              mySprite1.addChild(eastholder);
              mySprite1.addChild(westholder);                            
              this.addChild(mySprite1);
          }
     }
}


kicker
07-10-2008 @ 9:33 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

First thing is first why in god's name are you calling your image files through the URLLoader? Also if you insist on doing so you need to do it totally different than what you are to get a clear image. What is happening is you have the urlLoader loading and in mid stream showing the picture. Doesn't work well as you have seen. You need to have an event listener to listen for the completion of the URLLoader so you can be sure you got the whole file instead of a portion of it.

The other way you can do it is just load the source into an IMAGE component through it's property "source". That would solve the problem all together.

Craig

zionist
07-11-2008 @ 8:47 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 94
Joined: Feb 2007

hi this may sound funny but i am just learning how to do this in actionscript. i really dont understand how to do it. i have tried reading the flex actionscript docs but still confused. maybe an example will do. thanks

kicker
07-11-2008 @ 11:07 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

proper way to use a URLLoader:

public function getImage():void
{
   var myURLRequest:URLRequest = new URLRequest("../zoomin.png");
   var myURLLoader:URLLoader = new URLLoader();
   myURLLoader.addEventListener(Event.COMPLETE, loadImage);
   myURLLoader.load(myURLRequest);
}

private function loadImage(evt:Event):void
{
   var myLoadedURLLoader:URLLoader = evt.target as URLLoader;
   myImagecomponent.source = myLoadedURLLoader.data;
}

or to keep things simple:

myImageComponent.source = "../zoomin.png";

In your case I would use the the simple approach.

Craig

zionist
07-13-2008 @ 3:48 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 94
Joined: Feb 2007

am sorry am a little bit confused about the myImagecomponent.source = myLoadedURLLoader.data; i get this error when i try to add it to a sprite "1067: Implicit coercion of a value of type flash.net:URLLoader to an unrelated type flash.display:DisplayObject." this is my updated code snippet

"var middleholder:Sprite = new Sprite();
              middleholder.graphics.beginFill(0*000000);
              middleholder.graphics.drawCircle(0, 50, 6);
              middleholder.alpha = .5;
              var middleURLRequest:URLRequest = new URLRequest("../middle.png");
                  var middleURLLoader:URLLoader = new URLLoader();
                  middleURLLoader.addEventListener(Event.COMPLETE, function(evt:Event):void
               {
                       var myLoadedURLLoader:URLLoader = evt.target as URLLoader;
                       //myImagecomponent.source = myLoadedURLLoader.data;
               });
                  middleURLLoader.load(middleURLRequest);
                  middleholder.addChild(middleURLLoader);
              this.addChild(middleholder);"


kicker
07-13-2008 @ 9:55 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

Again I suggest the simple approach. Just directly call the the image into the Image component and forget the urlLoader. You are making things more complicated than you need to for a simple image.

Craig

zionist
07-16-2008 @ 8:43 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 94
Joined: Feb 2007

hi i think i finally got it to work, as in the png loads fully without being blured. for those who are intrested here is the solution although still cant get it to be inside the middleholder container maybe someone will figure it out.

var middleholder:Sprite = new Sprite();
    middleholder.graphics.beginFill(0*000000);
    middleholder.graphics.drawCircle(6, -50, 10);
    middleholder.alpha = 1;
    var middle:Loader = new Loader;
    var middle_url:URLRequest = new URLRequest("../middle.png");
    middle.load(middle_url);
    addChild(middle)
    middle.contentLoaderInfo.addEventListener(Event.COMPLETE, function(evt:Event):void
     {
          middleholder.addChild(middle.content);
     });     



Website Designed and Developed by Pablo Varando.