function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kevin LanguedocKevin Languedoc 

Flex

Hi
 
Basically I have a flex application embedded in a visualforce page and I need to pass the session id and url like in a scontrol
i.e.:
 <param name="flashvars" value="session_id={!API.Session_ID}&server_url={!API.Partner_Server_URL_90}" />
However when I try to save, I am getting errors that it is trying not finding API and wants to create a method in my controller class.
 
How can I get and pass the sessionid and url my my flex application from the VisualForce page.
 
Do I need to access it through a scontrol. If so how do I call a scontrol object in my visualforce or apex class?
 
 
 
code:
================================
 
<apex:page Controller="AccountInformationControl" tabstyle="Account">
 
    <script src="/soap/ajax/11.1/connection.js"></script>
    <script>
       function getAccountNo(){
          var accountNo = "{!AccountNumber}";
          return accountNo;
      }
     
      function getAccountName(){
         
        var accountName = "{!AccountName}";
          return accountName ;
      }
     
      function getOtherAccounts(){
         
     
      }
     
      function getSessionId(){
     
     
      }
     
      function getUrl(){
     
      }
  </script>
 
  <h1>DRAXIMAGE Sales Information</h1><br/>
             
             <apex:pageblock >
                 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
                  id="SFQueryBuilder" width="100%" height="303"
                  codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
                  <param name="movie" value="{!$Resource.SFQueryBuilder}" />
                 <param name="flashvars" value="session_id={!API.Session_ID}&server_url={!API.Partner_Server_URL_90}" />
                  <param name="quality" value="high" />
                  <param name="bgcolor" value="#869ca7" />
                  <param name="allowScriptAccess" value="sameDomain" />
                  <embed src="{!$Resource.SFQueryBuilder}" quality="high" bgcolor="#869ca7"
                    width="100%" height="421" name="SFQueryBuilder" align="middle"
                    play="true"
                    loop="false"
                    quality="high"
                    allowScriptAccess="sameDomain"
                    type="application/x-shockwave-flash"
                    pluginspage="http://www.adobe.com/go/getflashplayer">
                  </embed>
                </object>
           </apex:pageblock>
      <br/>
      </apex:page>
aalbertaalbert
Try using the syntax: {!$Api.Session_ID} and {!$Api.Partner_Server_URL_90} in your VF page.
Kevin LanguedocKevin Languedoc
Thanks for the reply it works. I also found another solution:
 
Since the Flex application was working perfectly in a scontrol, I decided to leave it there and embed the scontrol in my VF page by using the code:
 
<apex:scontrol name="NameOfMySControl" width="-100" heigth="350"/>
 
 
I works beautifully.... and I don't get the IE security warning about secure and unsecure content.
jeffdonthemicjeffdonthemic
You might want to take a look at the following link with code example as the <apex:flash> tag is now the preferred method of embedding content into a Visualforce page.

http://blog.jeffdouglas.com/2008/11/12/developing-salesforcecom-applications-with-flex-and-visualforce/

Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com
Kevin LanguedocKevin Languedoc
Thanks for the info....
 
I replace my code with the code you have suggested.
 
 
Yesterday the flex app was loading at a decent speed. Last night after I received my first response, I tried the suggestion from aalbert and the flex (static resource) woked fine. I also tried my own suggestion of using apex:scontrol and again the flex applicaton was loading at a decent rate and the queries were working.
 
 
However I short time later, the load perfomance dropped off significantly to the point it is taking more than 5 minutes for the flex application to load but the logi seems to fail. I tried in standalone mode the the load is sligty faster and the queries and working. It seems to be the as problem with the login.
 
I tried a plain flex application with no login and it is still fairly slow from a VF page (load time > 2  min).
 
From VF page
 
           <apex:flash src="{!$Resource.SFQueryBuilder}" 
        width="600" height="300" 
        flashvars="userId={!$User.Id}&session_id={!$Api.Session_ID}&server_url={!$Api.Partner_Server_URL_140}" /> 
 
 
 from flex app:
 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

layout="absolute"

xmlns:salesforce="com.salesforce.*"

applicationComplete="login();" height="302"

width="675" borderColor="#FBFBFB" backgroundGradientAlphas="[1.0, 1.0]"

backgroundGradientColors="[#EBF2F3, #EBF2F3]"

name="SFQueryBuilder">

<mx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

import com.salesforce.*;

import com.salesforce.results.QueryResult;

import com.salesforce.objects.LoginRequest;

import com.salesforce.objects.SObject;

import com.salesforce.AsyncResponder;

import flash.external.ExternalInterface;

import mx.utils.ObjectUtil;

import mx.controls.Alert;

import flash.events.Event;

[Bindable]

private var sfdc:Connection = new Connection();

private function login():void {

initVariables();

var lr:LoginRequest = new LoginRequest();

lr.server_url = Application.application.parameters.server_url;

lr.session_id = Application.application.parameters.session_id;

//test standalone

lr.username = 'klanguedoc@xxxxxxxxxxxxx';

lr.password = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

lr.callback = new AsyncResponder(loadData, handleFault);

apex.login(lr);

}

// initializes the building id variable

private function initVariables():void {

var modelId:String = Application.application.parameters.modelId;

sfdc.protocol = "https";

sfdc.serverUrl = "https://na6.salesforce.com/services/Soap/u/14.0";

}

private function handleFault(fault:Object):void {

Alert.show(ObjectUtil.toString(fault));

}

private function accountId():String {

var accountid:String = new String(ExternalInterface.call("getAccountNo"));

return accountid;

}

private function accountName():String{

var accountName:String = new String(ExternalInterface.call("getAccountName"));

return accountName;

}

[Bindable]

private var ar:ArrayCollection = new ArrayCollection;

// Display a selected item's label field and index for change events.

private function changeEvt(event:Event):void {

apex.query("Select Name from Account where AccountNumber='"+

event.currentTarget.selectedItem +"'",new AsyncResponder(

function(qr:QueryResult):void {

if (qr.size > 0) {

for (var j:int=0;j<qr.records.length;j++ ) {

txtCustName.text= qr.records[j].Name;

}

}

},

handleFault));

}

 

 

private function loadData(lr:Object):void {

apex.query("Select AccountNumber From Account where AccountNumber !=null ", new AsyncResponder(

function(qr:QueryResult):void {

if (qr.size > 0) {

for (var j:int=0;j<qr.records.length;j++ ) {

ar.addItem(qr.records[j].AccountNumber);

}

}

},

handleFault)

);

}

]]>

</mx:Script>

<salesforce:Connection id="apex" />

 

<mx:Canvas width="671" height="282" borderStyle="none" top="10" left="2" borderColor="#FBFBFB">

<mx:Label x="10" y="99" text="Customer No:" id="custNo" enabled="true"/>

<mx:ComboBox x="100" y="97" id="cbCustNo" enabled="true"

text="{accountId()}"

dataProvider="{ar}"

change="{changeEvt(event)}"

/>

<mx:Label x="268" y="99" text="Customer Name:" id="custName" enabled="true"/>

<mx:Text width="285" id="txtCustName" enabled="true" x="376" y="99" text="{accountName()}"/>

<mx:ComboBox x="100" y="127" id="cbProductNo"

editable="false"

enabled="true"></mx:ComboBox>

<mx:Label x="10" y="129" text="Product No:" id="prodNo" enabled="true"/>

<mx:DateField x="100" y="175" width="176" cornerRadius="0" showToday="true" enabled="true" id="dtStartDate"/>

<mx:Label x="10" y="177" text="Start Date:" id="startDate" enabled="true"/>

<mx:Label x="284" y="177" text="End Date:" id="endDate" enabled="true"/>

<mx:DateField x="376" y="175" width="176" id="dtEndDate" showToday="true"/>

<mx:Label x="268" y="129" text="Product Name:" id="prodName" enabled="true"/>

<mx:Text x="376" y="129" width="285" id="txtProdName" />

</mx:Canvas>

</mx:Application>

mtbclimbermtbclimber
The way described on Jeff's blog misses out on much of the value of Visualforce.  There is no leverage of components, tight binding with the controller, system integrity enforcement or minimization of server round trips.  Unless you are using flex for what flex is uniquely good for - graphic-intensive data visualization - you would be better served by using Visualforce components wherever possible.

For data visualizations, another architecture to consider that would minimize trips to the server would be to load the data into Javascript variables and have the flash movie load the data from the store on the client rather than go back to the server. Doing this will also reintroduce controller binding and system integrity enforcement.
Kevin LanguedocKevin Languedoc

I am using Flex becauseI am used to it and I find Flex Builder a powerful tool for UI development. Since I am new to VF I sought to minimize my learning curve. Tat said I tried to oad the data from the Account object troughthe controller but could never get it to work. See incuded code:

 

public class AccountInformationControl {

    private final Account account;
    private String AccountNumber;
    private String AccountName;
    private List<Account> accountNos;
   
 
   

    public AccountInformationControl() {
        account = [select accountNumber, name from Account where id = :ApexPages.currentPage().getParameters().get('id')];
    }
       

    public String getAccounts() {
        return null;
    }
   
    public String getAccountNo() {
        return null;
    }


    public String getAccountName() {
        AccountName = account.name;
        return AccountName;
    }


    public String getAccountNumber() {
        AccountNumber=account.accountNumber;
        return AccountNumber;
    }

 

     
      
    public List<Account> accounts(){
        accountNos = [Select AccountNumber from Account where AccountNumber !=null];     
       //List<Account> accountNo = new List<String>{'value1', 'value2', 'value3', 'value4' };

    return accountNos ;

    }
   
   
   
}

 

The Javascript/Apex code that I tried to used to load the data into a javascript array:

 

<script>var accounts = [];</script>

<apex:repeat value="{!accountNos}" var="accno">
        <script>accounts.push("{!accno}")</script>
</apex:repeat>

also tried:

<apex:repeat value="{!accountNos}" var="accno">
        <script>accounts.push("{!accno.AccounNmber}")</script>
</apex:repeat>

Any suggestions would be greatly appreciated since, as you said, I am leveraging the controller and have tigh data binding

mtbclimbermtbclimber
I am by no means a flex expert so I will look to other members of the community to chime in on your issues with pulling client side data into the flash movie.  I would like to ask what your requirements are, if not data visualization, as it might be a good opportunity to introduce you to working Visualforce more natively.

Cheers,
Kevin LanguedocKevin Languedoc
Good point about using VF more...:smileyhappy:  I will have plenty of opportunity to delve into VisualForce over the coming months since the people who are using Salesforce where I work have a lot of requirements for customization.
 
 
My requirements:
I need to create a reporting application that uses live data from an external database server. I also need to create a UI that resembles an Excel pivot table where users can manipulate the data. Flex has olap and advanced data grid components and Flex Builder offers some pretty impressive RAD.
 
The back end will be in asp.net web service.
 
I am also looking at Excel (and the web components) as a way to create a pivot table for some more advanced data manipulation because the owc supports pivot tables.
 
 
As a side note, I found the problem with Flex. My flash player crashed on my laptop sometime last night. Yesterday during the day I kept getting the Visual Studio debugger in IE7 several times when I tried to import my swf file either in s-control or static resources. This morning I couldn't load any Flex applications that we have running on our corporate server or they would several minutes (> 5 minutes) to load. So I tested my VF/Flex application and other Flex applications on different workstations at the office and they are working fine. So I re-installed my flash player and everything seems back to normal as far as running the Flex applications in Salesforce.
 
Best Regards,
 
Kevin
gv007gv007
all of you guys using flix tool kit or you are trying witha out that?
jeffdonthemicjeffdonthemic
We have a number of projects in production using the Flex toolkit but have recently begun switching to Adobe's open source BlazeDS. The AMF protocol is lightning fast and we just find it much easier to do backend development in Java rather than Actionscript. It also significantly reduces the size of the SWFs that are produced.

I have a small BlazeDS tutorial you can that you may find interesting:

http://blog.jeffdouglas.com/2008/12/05/blazeds-referenceerror/

You also might want to take a look at the Mate dependency injection framework for Flex. It makes large application development MUCH easier!

Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com
Kevin LanguedocKevin Languedoc

Thanks for the info.

 

I used Blazeds in the past. However my employer was recently bought out and the new owners are big Microsoft fans, so we had to switch to .NET. That being said, I recently setup weborb on a dev server. I tried a couple of the samples that came with weborb and they worked fine. However when I tried to re-create some test apps from Flex Developer Portal in Flex Builder I am getting a lot of access denied and policy file permission problems. I tried a crossdomain.xml file at the root without any luck. And I don't have time right now to try and figure out what I am doing wrong.

I will get back to that issue after my current project.

I will check out your tutorial and Mate

 

 

Thanks

 

Kevin

Kevin LanguedocKevin Languedoc

I am using the flex toolkit. The posts form the different guys offered invaluable information on getting everything running smoothly

 

Kevin