Hello,

On Wed, Mar 24, 2010 at 11:23 PM, Oleg Sivokon <[email protected]>wrote:

> 1. You cannot embed on constants.
> 2. It is always better to embed on a class then on a variable (you won't be
> using mx.core.WhateverAsset for the asset factory, but a normal flash.*
> class.
>
>
1) Are you sure? Embedding seems to work fine for the lines
        <mx:Button label="1" icon="{Symbols.SPADES}" />
        <mx:Button label="2" icon="{Symbols.CLUBS}" />
        <mx:Button label="3" icon="{Symbols.DIAMONDS}" />
        <mx:Button label="4" icon="{Symbols.HEARTS}" />

Also, I've changed from const to var in the

package {
    public class Symbols {
        [Embed('../assets/symbols.swf', symbol='spades')]
        public static var SPADES:Class;

and still get the same runtime error

ReferenceError: Error #1065: Variable SPADES is not defined.
    at global/flash.utils::getDefinitionByName()
    at TestCase/onCreationComplete()[C:\Documents and Settings\afarber\My
Documents\Flex Builder 3\TestCase\src\TestCase.mxml:21]
    at TestCase/___TestCase_Application1_creationComplete()[C:\Documents and
Settings\afarber\My Documents\Flex Builder 3\TestCase\src\TestCase.mxml:4]

2) Could you elaborate, I don't understand what you've written.

Can anyone please fix my test code?
Here is it again, it is very short:

package {
    public class Symbols {
        [Embed('../assets/symbols.swf', symbol='spades')]
        public static var SPADES:Class;

        [Embed('../assets/symbols.swf', symbol='clubs')]
        public static var CLUBS:Class;

        [Embed('../assets/symbols.swf', symbol='diamonds')]
        public static var DIAMONDS:Class;

        [Embed('../assets/symbols.swf', symbol='hearts')]
        public static var HEARTS:Class;
    }
}

-------------

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
    layout="absolute"
    creationComplete="onCreationComplete();">
    <mx:Script>
       <![CDATA[
           private function onCreationComplete():void
           {
                var sprite:Sprite = new Sprite();
                var g:Graphics = sprite.graphics;

                g.lineStyle(1, 0xFF0000);
                g.beginFill(0xFF0000);
                g.drawCircle(100, 100, 20);
                g.endFill();

                   spriteHolder.addChild(sprite);

                // XXX stuff below not working, can it be fixed?
                   var suit:String = "SPADES";
                   var mc:MovieClip = new
(getDefinitionByName("Symbols.SPADES") as Class);
                   spriteHolder.addChild(mc);
           }
       ]]>
    </mx:Script>
    <mx:VBox width="100%">
        <mx:Button label="1" icon="{Symbols.SPADES}" />
        <mx:Button label="2" icon="{Symbols.CLUBS}" />
        <mx:Button label="3" icon="{Symbols.DIAMONDS}" />
        <mx:Button label="4" icon="{Symbols.HEARTS}" />
         <mx:UIComponent id="spriteHolder" width="200" height="200"/>

    </mx:VBox>
</mx:Application>

Reply via email to