Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-12-2007, 09:13 AM   #1
Roaders
Registered User
 
Join Date: Sep 2003
Posts: 3
Default help with image embed problem

Hi Guys

I have this code:

Code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
        	import mx.controls.Image;
            [Embed(source="/assets/logo.swf")]
            [Bindable]
            public var imgCls:Class;
		
			private function testPrint():void
			{
				var testImage:Image = new Image();
				testImage.source = "{imgCls}";
				this.addChild(testImage);
			}
        ]]>
    </mx:Script> 

    <mx:Button label="Icon Button 1" icon="{imgCls}" click="testPrint()"/>
    <mx:Button label="Icon Button 2" icon="{imgCls}"/>
</mx:Application>
Based on an example from the adobe site. The images in the buttons work fine but the image that is attached just appears as a broken image. I've been trying to get this to work since Friday and it seems like it should be very simple!

Hope someone can help.

Thanks
Roaders is offline   Reply With Quote
Old 03-12-2007, 05:41 PM   #2
dr_zeus
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

Code:
testImage.source = "{imgCls}";
I don't think this line will work. Binding should be done in MXML. Did you try the following?

Code:
testImage.source = imgCls;
__________________
Josh Tynjala | Feathers
dr_zeus is offline   Reply With Quote
Old 03-12-2007, 10:22 PM   #3
Roaders
Registered User
 
Join Date: Sep 2003
Posts: 3
Default

Thanks for the reply.

In fact I just needed to add an event listener, something like this:

Code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
        	import mx.controls.Image;
            [Embed(source="/assets/logo.swf")]
            [Bindable]
            public var imgCls:Class;
		
			private function testPrint():void
			{
				var testImage:Image = new Image();
				testImage.addEventListener(FlexEvent.CREATION_COMPLETE, loadImage);
				this.addChild(testImage);
			}

			private function loadImage(e:Event):void
			{
                                Image(e.currentTarget).load(imgCls);
			}

        ]]>
    </mx:Script> 

    <mx:Button label="Icon Button 1" icon="{imgCls}" click="testPrint()"/>
    <mx:Button label="Icon Button 2" icon="{imgCls}"/>
</mx:Application>
Roaders is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wierd dynamic image problem... Von679 ActionScript 2.0 2 07-01-2008 05:06 AM
FREE Image Gallery Code UPDATED w00t w00t!! flavoredthunder ActionScript 1.0 (and below) 2 12-22-2006 01:18 PM
Image scale effect performance problem JoeJohn ActionScript 2.0 2 03-23-2006 09:29 PM
loading image Dynamically, small problem Matsko ActionScript 2.0 1 09-27-2004 07:15 AM
Loading image problem... 7of9 ActionScript 1.0 (and below) 8 08-11-2003 03:47 PM


All times are GMT. The time now is 12:42 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.