A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: How to integrate flash and flex?

  1. #1
    Junior Member
    Join Date
    Nov 2006
    Posts
    9

    How to integrate flash and flex?

    I need to send parameters from flex to flash. I have read this article http://www.actionscript.org/resource...her/Page1.html

    This example is rather simple and it works when I send parameters from flash to flex, but how to do it in other direction? for example when I press button in flex my flash application should show some message.
    If it isn't very difficult to you please write a code.

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    It works very similar in Flex. In Flash it is a bit different.
    Flex
    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="200" width="200">
        <mx:Script>
        public function clickHandler(event:Event):void
        {
            clickedButton = "Yeah, this works.";
               myText.text = clickedButton;
               dispatchEvent(new Event("clicked"));
        }
    </mx:Script>
        <mx:Button x="38" y="31" label="press" id="but" click="clickHandler(event)"/>
        <mx:TextArea x="20" y="103" id="myText"/>
        <mx:String id="clickedButton"/>
    </mx:Application>
    Flash
    PHP Code:
    var URL:String "bin/fk2.swf";
    var 
    urlRequest:URLRequest = new URLRequest(URL);
    var 
    urlLoader:Loader = new Loader();
    var 
    myDispatcher:IEventDispatcher urlLoader.contentLoaderInfo;
    //
    myDispatcher.addEventListener(Event.COMPLETEcompleted);
    function 
    completed (event:Event):void
    {            
        
    urlLoader.content.addEventListener(Event.ADDEDmyHandler); 
        function 
    myHandler(event:Event)
        {
             
    event.target.addEventListener("clicked"clickHandler); 
        }
        function 
    clickHandler (event:Event):void
        
    {
            var 
    clButton:String event.target["clickedButton"];
               
    trace(clButton);
            
    myText.text clButton;
        }
        
    }
    urlLoader.load(urlRequest);
    this.addChild(urlLoader);
    myText.text "not clicked"
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Nov 2006
    Posts
    9
    It's good, but how can you do this without urlLoader? I don't really need to load flex application inside flash(I have already loaded flash inside flex). I have flex application and a flash inside it. So I want to send parameters from flash to flex and I did this and in other direction. How to add event withoud using urlLoader?

    http://www.newviewnetworks.com/nvnho...iew/index.html
    This example works but the code for flash application is written in first frame, but my code is in a class which is written in the field document class. And when it in this class this code doesn't work
    Last edited by kitmaster; 12-08-2006 at 04:20 PM.

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You can easily get data from the parent by getting the clickedButton value directly. Here is the script in such case, which goes into the flash movie.

    PHP Code:
    someButton.addEventListener(MouseEvent.CLICKcHandler);

    function 
    cHandler(event:Event):void
    {
        var 
    myFlex:Object event.target.parent.parent.parent.parent;
        
    myFlex.addEventListener(Event.ENTER_FRAMEfindHandler); 
        function 
    findHandler(event:Event):void
        
    {
            if(
    myFlex["clickedButton"] != null)
            {
                
    myText.text myFlex["clickedButton"];
                
    removeEventListener("enterFrame"findHandler);
            }
            else
            {
                
    myText.text "null";
            }
        }
    }
    myText.text "not clicked"
    You can delete the dispatchEvent function in the flex movie.
    Last edited by cancerinform; 12-09-2006 at 04:29 PM.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I don't know you ever solved your problem, but here are the files attached, which work as Document classes to communicate with Flex both ways.
    Attached Files Attached Files
    - The right of the People to create Flash movies shall not be infringed. -

  6. #6
    Junior Member
    Join Date
    Nov 2006
    Posts
    9
    Thank you. I use localconnection now. It is rather simlier than this method. Don't you think so?

  7. #7
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I prefer localconnection only for interaction of two separate movies, but not for interaction of parent and child movies.
    Last edited by cancerinform; 12-12-2006 at 06:24 PM.
    - The right of the People to create Flash movies shall not be infringed. -

  8. #8
    Member
    Join Date
    Nov 2005
    Posts
    68

  9. #9
    Banned
    Join Date
    Dec 2006
    Posts
    18

    Re:

    I was trying to solve that too, without success.


    -------------------------------------------
    What music do you like?
    destinys child fans site
    http://www.destinys--child.com

  10. #10
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Post your code. May be until next year we can solve it
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center