Click here to Skip to main content
15,902,852 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have my friends work and he's not around so I want to try a little bit of Adobe Flex 4.

Here's the code:

C#
<?xml version="1.0" encoding="utf-8"?>
<s:Application creationComplete="application1_creationCompleteHandler(event)" xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" preloaderChromeColor="#FFFFFF" backgroundColor="#FFFFFF" width="1165">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.DragEvent;
            import mx.events.FlexEvent;
            import mx.graphics.ImageSnapshot;
            import mx.graphics.codec.JPEGEncoder;
            import mx.graphics.codec.PNGEncoder;
            import org.osmf.layout.AbsoluteLayoutFacet;

            var currimg:Image;
            var db:Array = new Array();
            var first:String;
            private function configureListeners(dispatcher:IEventDispatcher):void {
                dispatcher.addEventListener(Event.COMPLETE, completeHandler);
                dispatcher.addEventListener(Event.OPEN, openHandler);
                dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
                dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
                dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
                dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            }

            private function completeHandler(event:Event):void {
                var loader:URLLoader = URLLoader(event.target);

                var i : Number = 0;
                //
                var px:int = 90;
                var py:int = 50;
                var larr:Array = loader.data.toString().split(",");
                mx.controls.Alert.show(loader.data.toString());
                for each( var str:String in larr )
                {
                    if(str.indexOf(".db")<=0 && str!="")
                    {
                        var img1:Image = new Image();
                        img1.source = first+"/"+str;
                        img1.width = 50;
                        img1.height = 50;

                        img1.addEventListener(MouseEvent.CLICK,dothis);
                        logobar.addChild(img1);
                        db.push(img1);
                        img1.move(px,py);
                        px += img1.width+20;
                    }
                    i++;
                }

            }
            private function openHandler(event:Event):void {
                trace("openHandler: " + event);
            }
            private function progressHandler(event:ProgressEvent):void {
                trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
            }
            private function securityErrorHandler(event:SecurityErrorEvent):void {
                trace("securityErrorHandler: " + event);
            }
            private function httpStatusHandler(event:HTTPStatusEvent):void {
                trace("httpStatusHandler: " + event);
            }
            private function ioErrorHandler(event:IOErrorEvent):void {
                trace("ioErrorHandler: " + event);
            }

            private var bi:Array = new Array();

            private function saveImageToFileSystem():void
            {
                var jPEGEncoder:PNGEncoder = new PNGEncoder();
                var imageSnapshot:ImageSnapshot = ImageSnapshot.captureImage(imgCanvas, 0, jPEGEncoder);
                var fileReference:FileReference = new FileReference();
                fileReference.save(imageSnapshot.data, "img123.jpg");
            }

            protected function button1_clickHandler(event:MouseEvent):void
            {
                saveImageToFileSystem();
            }

            protected function button2_clickHandler(event:MouseEvent):void
            {
            imgCanvas.removeChild(currimg);
            }

            private function loadurl(url:String):void
            {
                var loader:URLLoader = new URLLoader();
                configureListeners(loader);
                var request:URLRequest = new URLRequest(url);
                try {
                    loader.load(request);
                }
                catch (error:Error) {
                    trace("Unable to load requested document.");
                }

            }
            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                bi.push("blue.jpg,tshirt_blue.png");
                bi.push("black.jpg,tshirt_black.png");
                bi.push("green.jpg,tshirt_green.png");
                bi.push("yellow.jpg,tshirt_yellow.png");
                bi.push("orange.jpg,tshirt_orange.png");
                bi.push("violet.jpg,tshirt_violet.png");
                var py:int = 50;


                for(var i:int=0; i<bi.length; i++)
                {
                    var arr:Array = (bi[i] as String).split(",");
                    var image:customimg = new customimg(arr[0],arr[1]);
                    image.addEventListener(MouseEvent.CLICK,changets);
                    logobar.addChild(image);
                    image.move(0,py);
                    py += image.height+20;
                }
                imgCanvas.addEventListener(MouseEvent.MOUSE_UP,stopdrag);
            }

            private function dothis(event:MouseEvent):void
            {
                var img:Image = new Image();
                img.width = 50;
                img.height = 50;
                img.source = (event.currentTarget as Image).source;
                img.addEventListener(MouseEvent.MOUSE_DOWN,dragme);
                img.addEventListener(MouseEvent.MOUSE_UP,stopdrag);
                imgCanvas.addChild(img);
            }

            private function dragme(event:MouseEvent):void
            {
                currimg = event.currentTarget as Image;
                (event.currentTarget as Image).startDrag(true);
            }

            private function stopdrag(event:MouseEvent):void
            {
                currimg.stopDrag();
            }

            private function changets(event:MouseEvent):void
            {
                theshirt.source = (event.currentTarget as customimg).tsimg;
            }

            protected function button3_clickHandler(event:MouseEvent):void
            {
                for(var i=0; i<db.length; i++)
                {
                    logobar.removeChild(db[i] as Image);
                }
                db =  new Array();
                first="image/logo";
                loadurl("index.php?m=logo");
            }

            protected function button4_clickHandler(event:MouseEvent):void
            {
                for(var i=0; i<db.length; i++)
                {
                    logobar.removeChild(db[i] as Image);
                }
                db =  new Array();
                first="image/text";
                loadurl("index.php?m=text");
            }
        ]]>
    </fx:Script>
    <mx:Canvas id="imgCanvas" width="527" height="407" x="23" y="30">
        <mx:Image id="theshirt" source="image/tshirt/tshirt_white.png" x="61" y="27"/>
    </mx:Canvas>
    <s:Button x="775" y="180" label="Save" click="button1_clickHandler(event)"/>
    <s:Button x="689" y="181" label="Delete" click="button2_clickHandler(event)"/>
    <mx:Canvas id="logobar" x="558" y="30" width="551" height="135" backgroundColor="#FFFFFF">
        <s:Label x="10" y="10" text="T Shirt Color"/>
        <s:Button x="155" y="10" label="Logo" click="button3_clickHandler(event)"/>
        <s:Button x="240" y="10" label="Text" click="button4_clickHandler(event)"/>
    </mx:Canvas>

    <fx:Declarations>

    </fx:Declarations>
</s:Application>





The problem is I uploaded all the files to my domain (public html).

It's certainly load the page but the child images (the logo) can't load.

I saw in the code that there is a loadurl(index.php?=text)

Am I need to create a page index.php?

I don't know how to do that.

Can someone help me?

Here's the link of my temporary domain
http://75.126.247.111/~phildogb/[^]
Posted
Updated 6-Mar-11 13:49pm
v2

1 solution

up still no one answer T T i hope someone who could help me
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900