Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

flex 3 combo box code

// description of your code here
Easiest way to populate a combo box.

var valueArray:Array = new Array();
          var emptyItem:Object = new Object();
          emptyItem.data = "";
          emptyItem.label = "";
          var buildingItem:Object = new Object();
          buildingItem.data = "building";
          buildingItem.label = "Building";
          var regionItem:Object = new Object();
          regionItem.data = "region";
          regionItem.label = "Region"        
          valueArray.push(emptyItem);
          valueArray.push(buildingItem);
          valueArray.push(regionItem);          
          
          filterComboBox = new ComboBox();
          filterComboBox.dataProvider = valueArray;
          filterComboBox.addEventListener(ListEvent.CHANGE, filterUpdate);

Embedded Fonts in Modules

How to use embedded fonts in modules and late-load the embedded font.
Save TrueType font file as ./Arial.ttf
@font-face {
        src:url("./Arial.ttf");
        font-family: myFont;
}

Application
{
	font-family: 	myFont;
	font-size: 	10px;
}

将flex 中的某个组件放到显示列表顶层

// description of your code here

function toTop(obj:UIComponent):void{
		
			if(obj.parent){
			  var parent:UIComponent = UIComponent(obj.parent);
				parent.swapChildren(obj,parent.getChildAt(parent.numChildren-1));
				if(!(parent is Application)){
					toTop(parent);
				}
			}
		}

Some Flex Code

// A login box component in mxml. This is buggy, I'll adjust this to the clean stuff when I get it figured out.
<?xml version="1.0" encoding="UTF-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" label="Login">
  <mx:Form labelWidth="150">
  <mx:Metadata> 
      [Event(name="login", type="com.pomodo.events.LoginEvent")] 
  </mx:Metadata> 
  <mx:Script> 
  <![CDATA[ 
    import mx.controls.Alert; 
    import mx.rpc.events.ResultEvent;
    import com.pomodo.events.LoginEvent; 
      private function login():void { 
          svcAccountLogin.send({login: loginTI.text, password: passwordTI.text}); 
      } 
      private function handleAccountLoginResult(event:ResultEvent):void { 
          var result:Object = event.result; 
          if (result == "badlogin") { 
              Alert.show("The username or password is wrong.", "Login Error"); 
          } else { 
              dispatchEvent(new LoginEvent(XML(result))); 
          } 
      } 
  ]]> 
  </mx:Script> 
  <mx:HTTPService 
      id="svcAccountLogin" 
      url="/sessions/create_xml" 
      resultFormat="e4x" 
      method="POST" 
      result="handleAccountLoginResult(event)"/>

    <mx:FormItem label="Username" required="true">
      <mx:TextInput id="loginTI"/>
    </mx:FormItem>
    <mx:FormItem label="Password" required="true">
      <mx:TextInput id="passwordTI"/>
    </mx:FormItem>
    <mx:FormItem>
      <mx:Button id="loginButton" label="Login" click="login()"/> 
    </mx:FormItem>
  </mx:Form>
</mx:VBox>

Flex/ActionScript: Making trace() display the method it was called in

While trace() is useful, its indiscriminate use by me often crowds
the console of my fellow developers. We agreed on making every trace() show
the method it came from, but I am too lazy to do this, this makes it automatic:

public static function TRACE(s:Object):void {
  try {
    throw new Error();
  } catch (e:Error) {
    var stack:String = e.getStackTrace();
    var frames:Array = stack.split("\n");
    var myFrame:String = String(frames[2]);
    myFrame = myFrame.replace("\t", "");
  
    // "at " can be followed by some part of the package
    // you don't want to see. E.g., if your code is all in
    // com.foo.bar, you can put "at com.foo.bar." so as not
    // to crowd the display
    myFrame = myFrame.substr("at ".length);
    myFrame = myFrame.substring(0, myFrame.indexOf("["));
    trace(myFrame + ": " + s);
  }
}

Converting file list into a class list

Converting file list into a class list - this is particularly useful for include-classes attribute of compc task in Flex, but may be useful for Java. The <chainmapper> is most probably pleonastic but it works for me this way, and I don't feel like trying it without it...

   <path id="xmlrpc_class_list_1">
      <fileset dir="${user.dir}/xmlrpc">
         <include name="com/mattism/**"/>
         <exclude name="**/Test*"/>
      </fileset>
   </path>
   <pathconvert 
      property="xmlrpc_class_list_2" 
      pathsep=" " 
      dirsep="." 
      refid="xmlrpc_class_list_1">
      <map from="${user.dir}/xmlrpc/" to=""/>
      <mapper>
         <chainedmapper>
            <globmapper from="*.as" to="*"/>
         </chainedmapper>
      </mapper>
</pathconvert>
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS