Fx script block help!!

888
6
Jump to solution
02-28-2012 10:11 PM
AnN
by
New Contributor
I am so new, trying to learn the basics of flex!!
I am not sure how the <fx:script> blocks work when there are more than one?! In my case, the script block within a control has no knowledge of the anything else outside of it!!!

For example, the codes below... Please look toward the end at function "protected function pubMapThumb_clickHandler(event:MouseEvent):void".

Within this function, I could not access anything "outside", like the "pubmapList" or any functions in the main <fx:script> block.

Can someone explain that to me, and how would I achieve in doing that? (access "outside" controls).

Thanks so much!!!

[INDENT]
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
   xmlns:s="library://ns.adobe.com/flex/spark"
   xmlns:mx="library://ns.adobe.com/flex/mx"
   width="1072" height="800" x="0" y="150"
   horizontalCenter="0" verticalCenter="0">

<fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
 
</fx:Declarations>

<fx:Script>
  <![CDATA[
  
   import mx.collections.*;
  
   [Bindable] public var imgArray:Array = new Array();
  
   public function createDataProvider():ArrayList
   {
    //var imgArray:Array = new Array();
    for(var i:int=0; i<9; i++)
    {
     imgArray = PathToMyImage();
    }
   
    return new ArrayList(imgArray);
   }
  
   private function PathToMyImage():String
   {
    return "http://arcgisonline.com/sharing/content/items/0bb40265b64a4b29ac3bccb774413357/info/thumbnail/global_wetlands.jpg";
   }
  ]]>
 
</fx:Script>

<mx:Text id="PubMapTitle" text="FEATURED MAPS" fontSize="36" y="45" horizontalCenter="0"/>

<s:List id="pubmapList"
   dragEnabled="false" dropEnabled="false" dragMoveEnabled="false"
   dataProvider="{createDataProvider()}"
   y="110" horizontalCenter="0">
   
  <s:layout>
   <s:TileLayout id="pubmapListTiles"
        verticalGap="10" horizontalGap="10" horizontalAlign="center" verticalAlign="middle" />
  </s:layout>
 
  <s:itemRenderer>
   <fx:Component>
    <s:DataRenderer>
    
     <fx:Script>
      <![CDATA[
       import flash.net.getClassByAlias;
      
       import mx.controls.Alert;
       import mx.core.UIComponent;
      
       public var uicomp:UIComponent;
      
       protected function image1_mouseOverHandler(event:MouseEvent):void
       {
        // TODO Auto-generated method stub
        //Alert.show("Map Info: " + "\n", "Map Details");
        //rollOverTextArea.visible = true;
        //rollOverTextArea.text = "Map Info";
        //rollOverTextArea.x = pubMapThumb.width.valueOf() + 10;
       
        pubMapThumb.toolTip = "Our Far South - Beyond Stewart Island (ArcGIS Viewer for Public)Live ArcGIS.com Map of the \"Our Far South\" Expedition to Antarctica";
       }
      
       protected function image1_mouseOutHandler(event:MouseEvent):void
       {
        // TODO Auto-generated method stub
        //rollOverTextArea.visible = false;
        //rollOverTextArea.text = "";
       }
      
       protected function pubMapThumb_clickHandler(event:MouseEvent):void
       {
        // TODO Auto-generated method stub
        //removeElement(uicomp);
       
        uicomp = new UIComponent();
        addElement(uicomp);
       
        var mapmodule:MapModule = new MapModule();
        mapmodule.setMapServer("http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer");
        mapmodule.width = Capabilities.screenResolutionX;
        mapmodule.height = Capabilities.screenResolutionY * .80 - 160;
        uicomp.addChild(mapmodule);
       }
      
      ]]>
     </fx:Script>
    
     <s:BorderContainer includeInLayout="true" id="imgBorderContainer" borderWeight="3" borderStyle="solid">
      <s:Image id="pubMapThumb" source="{data}" height="200" width="300" mouseOver="image1_mouseOverHandler(event)" mouseOut="image1_mouseOutHandler(event)" click="pubMapThumb_clickHandler(event)"/>
     </s:BorderContainer>
    </s:DataRenderer>
   </fx:Component>
  </s:itemRenderer>
</s:List>
</s:Group>
[/INDENT]
Tags (2)
0 Kudos
1 Solution
6 Replies
JHayes
by
Occasional Contributor
Hello,

As far as I know, you should only have one script block and all you methods in it.  I've never seen Flex code with more that 1.

Joe
0 Kudos
KenBuja
MVP Esteemed Contributor
Hello,

As far as I know, you should only have one script block and all you methods in it.  I've never seen Flex code with more that 1.

Joe


As shown in Dasa's link, it is possible to have more than one script block. A better question would be why it's advantageous to have more than one block.
0 Kudos
JHayes
by
Occasional Contributor
OK.  Why is it advantageous to have more than one script block?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Well as long as we are just chatting here...
The obvious reason more than one script block would be advantageous is when, like the original posters situation you are doing inline itemRenderers and inline components and need to do some AS3 in the component.
0 Kudos
JHayes
by
Occasional Contributor
My bad guys - I didn't take the time to fully understand the question.  Point taken.
0 Kudos