3 Replies Latest reply on Apr 12, 2010 8:45 AM by dakasadakasadaka

    ActionScript class in the s:panel

    dakasadakasadaka

      Hello just some newbie question: I have actionscript file like:

       

      package
      {           
      import flash.net.NetConnection;
                  import flash.events.NetStatusEvent;
                  import flash.media.Camera;
                  import flash.media.Video;
                  import flash.display.Sprite;
                  import StreamAV;

       

      public class broadcastNow extends Sprite
        {
              private    var nc:NetConnection;
              private    var cam:Camera;
              private    var vid:Video;
              private    var rtmpNow:String;
              private    var broadcasting:StreamAV;
              private    var good:Boolean;

       


                          public function broadcastNow():void
                          {

       

                               //Set Camera and Microphone

       

                               nc=new NetConnection ;
                               nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
                               cam=Camera.getCamera();
                               cam.setMode(240,180,15);
                               cam.setQuality(0,85);
                               vid=new Video(240,180);
                               vid.x=150;
                               vid.y=90;
                               addChild(vid);
                               rtmpNow="rtmp://ip-adress/test1";
                               nc.connect (rtmpNow,"anchor");
                          }

       

                          //Connection
                          private function checkConnect (e:NetStatusEvent):void
                          {
                               good = e.info.code == "NetConnection.Connect.Success";
                               trace(e.info.code);
                               if (good)
                               {
                                    
                                     broadcasting=new StreamAV(nc);
                                     vid.attachCamera (cam);
                                     broadcasting.streamOut (cam,"presentation");
                               }
                          }
        }
      }

       

      an I made some flex app like this: my index.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application 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="1024" minHeight="768"
          xmlns:components="components.*"
          >
         
              <!-- Properties of the parent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
          <s:layout>
             
              <s:VerticalLayout
                  paddingLeft="25"
                  paddingTop="25"
                  paddingRight="25"/>
             
          </s:layout>
         
          <!-- Metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
       
          <s:ButtonBar dataProvider="{homeStack}"/>
         
          <mx:ViewStack id="homeStack"
              resizeToContent="true">
             
              <components:ownersHome label="Home"/>
         
              <components:ownersObjects label="add/edit/delete Objects" />
         
              <components:ownersFaq label="FAQ" />
             
          </mx:ViewStack>
      </s:Application>

       

      and my ownersHome.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:mx="library://ns.adobe.com/flex/mx"
          xmlns:components="componentsOfHome.*"
         
          >
         
          <!-- Properties of the parent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
          <s:layout>
              <s:BasicLayout />
          </s:layout>
         
          <!-- Metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
          <s:HGroup x="20"
             gap="20"
             width="100%"
             right="20" left="20"
             bottom="20" top="20">
             
              <components:ownersCams label="Cams"/>
         
              <components:ownersStats label="Stats" />
         
              <components:ownersChat label="Chat" />
             
         </s:HGroup>
         
      </s:NavigatorContent>

      an finally ownersCam an that's what is all about I want to have above actionscript file placed into s:Panel and hier are the codes of ownersCam:

      <?xml version="1.0" encoding="utf-8"?>
      <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:mx="library://ns.adobe.com/flex/mx"
          xmlns:custom="*"
          >
          <!-- creationComplete="broadCastMeNow()" -->
         
          <!-- Properties of the parent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
          <s:layout>
              <s:VerticalLayout paddingLeft="15" paddingRight="15" paddingTop="15"
                  gap="15"/>
          </s:layout>
         
          <!-- Metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
         
         
          <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
          <fx:Script>
              <![CDATA[
                  import broadcastNow;
                  [Bindable]
                  private var broadCastMe:broadcastNow;
                  public function broadCastMeNow(event:Event):void
                  {
                      broadCastMe = new broadcastNow()
                  }
              ]]>
          </fx:Script>
         
          <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         
          <fx:Declarations>
                  <custom:broadcastNow />   
          </fx:Declarations>-->
         
          <!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         
          <s:Panel title="Cams">
                <mx:Button
                  id="submitButton" label="Search"
                  click="broadCastMeNow(event);"
        />
          </s:Panel>
      </s:NavigatorContent>

       

      But it doesn't work.....Matbe I need to place it into something other and not to s:Panel !!!

      tnx.

      daka

      Website Bouwen

        • 1. Re: ActionScript class in the s:panel
          Flex harUI Adobe Employee

          I"m not sure what didn't work, but in Flex, children have to be

          IVisualElements and Sprite is too low-level to implement that.  There is a

          SpriteVisualElement though

          1 person found this helpful
          • 2. Re: ActionScript class in the s:panel
            dakasadakasadaka Level 1

            tnx for reply... now I have it on stage but not in the s:Panel

             

            it is always on the same coordinates and I can't change position of the SpriteVisualElement....

            it should go inside the Panel, I think!!! But it's not!

             

            hier is how the code looks like:

             

            <fx:Script>
                    <![CDATA[
                        import broadcastNow;
                        public function broadCastMeNow(event:Event):void
                        {
                            var broadCastMe:broadcastNow = new broadcastNow();
                            connn.addChild(broadCastMe)               
                        }
                    ]]>
                </fx:Script>

             

            <s:Panel width="100%" title="Cams">
                     <s:Group width="80">
                         <mx:Button
                            id="submitButton" label="Search"
                            click="broadCastMeNow(event);" />
                        <s:SpriteVisualElement bottom="10" id="connn" />
                    </s:Group>
                </s:Panel>

            • 3. Re: ActionScript class in the s:panel
              dakasadakasadaka Level 1

              tnx that workt wel finnally