The migration isn't so painful once you really get your head around 
concepts in Flex.

Thanks to everyone for their replies to this initial post. I posted 
on the actionscript.org forum at the same time, and got some very 
helpful advice from a user named Sly_cardinal. 

I thought I would post it here for the benefit of all.

One additional note: after I figured out how to get at the clips 
within a SWF, I wanted to populate an array with a list of those 
clips. Then I can call them with a function to apply a color from a 
colorpicker. 

The code uses SWFloader to load "kj_complete.swf" then parses the 
individual parts of the artwork (a basketball uniform, BTW) into an 
array. The 'change' method on the ColorPicker control calls the 
function to apply color to an individual part.

The artwork was created in Illustrator, then all objects were 
converted to symbols, imported into Flash CS3 and placed on the stage.

I'm thinking I can skip the step of placing the artwork on the stage 
with additional AS code, but I just needed to get this working.

Sorry, but I can't post the actual artwork (non-disclosure agreement) 
but I thought everyone could benefit from the code.

Here's my code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
    creationComplete="creationCompleteHandler(event)">
    
    <mx:Script>
        <![CDATA[
            //import necessary classes (I could make this list 
shorter by using *)
            import mx.core.MovieClipAsset;
            import flash.display.DisplayObject;
            import flash.display.DisplayObjectContainer;
            import flash.geom.ColorTransform;
            import mx.controls.SWFLoader;
            import mx.events.FlexEvent;
            import flash.events.Event;
            import flash.events.MouseEvent;
            import flash.display.MovieClip;
            import flash.display.InteractiveObject;
            import mx.collections.*;
            import mx.events.ColorPickerEvent;
            import mx.events.DropdownEvent;
            
            private var uniPart:Array;
            
            //function to ensure SWF is completely loaded
            public function creationCompleteHandler 
(event:FlexEvent):void
            {
                swfLoader.addEventListener(Event.INIT, initHandler);
                swfLoader.source = "assets/kj_complete.swf";
            }
            
            //function to extract content from SWF
            public function initHandler(event:Event):void
            {
                var content:DisplayObjectContainer = 
DisplayObjectContainer(SWFLoader(event.target).content);
                // Call loadUniform here, set uniPart to result.
                uniPart = loadUniform();
            }

            //function to parse clip names into an array            
            private function loadUniform():Array
            {
                var content:DisplayObjectContainer = 
DisplayObjectContainer(SWFLoader(swfLoader).content);
                var uniPart:Array = new Array();        
                uniPart[0] = MovieClip(content["jersey_body"]);
                uniPart[1] = MovieClip(content["jersey_panel1"]);
                uniPart[2] = MovieClip(content["jersey_panel2"]);
                uniPart[3] = MovieClip(content["v_neck"]);
                uniPart[4] = MovieClip(content["vneck_insert"]);
                return uniPart;
            }         
            
            //function to change color when colorpicker is changed
            private function changeColor 
(event:ColorPickerEvent,object:int):void {
                var uniSwatch:MovieClip = uniPart[object];
                var colorSwitch:ColorTransform = 
uniSwatch.transform.colorTransform;
                colorSwitch.color = event.target.selectedColor;
                uniSwatch.transform.colorTransform = colorSwitch;
            }
        ]]>
    </mx:Script>
        
    <mx:VBox width="770" height="700" backgroundColor="#FFFFFF" x="0" 
y="0">
        <mx:ColorPicker id="cp"
            showTextField="true"
            selectedColor="0xFFFFFF"
            change="changeColor(event,0);" 
            editable="false"/>
        <mx:SWFLoader id="swfLoader" />    
    </mx:VBox>
</mx:Application>


Reply via email to