[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 578
  • Last Modified:

Correct AS3 syntax for

First off, I only know enough about Flash to be dangerous! I'm trying to port over some AS2 code to AS3 code. My issue is I get a compiler error on this:

s.dc=112;

error:
Implicit coercion of a value of type int to an unrelated type String

If I try something like:

var s.dc:Number=112;

I get the following error:

Syntax error: expecting semicolon before dot

What is the syntax? Code is below

import com.omniture.ActionSource;
var s:ActionSource;
function configActionSource() {
 
	s = new ActionSource();
 
	s.account = "comdev";
 
	s.pageName = "MyVideoPageName";
	s.pageURL = "";
 
	s.charSet = "UTF-8";
	s.currencyCode = "USD";
 
	s.trackClickMap = true;
	s.movieID = "Example 1";
	s.Media.autoTrack= true;
	s.Media.trackWhilePlaying = true;
	s.Media.playerName = "EA Player Name2"
	s.Media.trackSeconds=5;
	s.Media.trackVars="events,prop1,prop2,prop3,prop4,prop5,prop6,prop7,prop8,prop9,prop10,prop11,prop12,eVar1,eVar2,eVar3";
	
	s.Media.trackEvents="event1,event2,event3,event4,event5";
 
	s.prop1="LABLE/BUSINESS_UNIT";
	s.prop2="STUDIO_NAME";
	
	
	s.events="event1,event2";
		
	s.debugTracking = true;
	s.trackLocal = true;
 
	s.visitorNamespace = "eaeacom";
	//var s.dc:Number=112;
	//s.dc=112;
	var s.dc:Number=112;
 
 
	addChild(s);
}
configActionSource();
s.Media.monitor = function (s,media) {
	
	if(media.event=="OPEN") {
		s.events="event1";
		s.eVar1="evar1Value";
		s.prop1="LABLE/BUSINESS_UNIT";
	}
	
	var tracked25:Boolean=false;
	var tracked35:Boolean=false;
	var tracked50:Boolean=false;
	var tracked60:Boolean=false;
	var tracked75:Boolean=false;
	var tracked85:Boolean=false;
	
	if ((!tracked25) && (media.percent >= 25)) {
		s.events="event2";
		s.prop2="STUDIO_NAME";
		s.eVar2="evar2Value";
		
		s.Media.track(media.name);
		tracked25=true;
	}
	
	if ((!tracked35) && (media.percent >= 35)) {
		
		s.Media.track(media.name);
		tracked35=true;
	}
 
	if ((!tracked50) && (media.percent >= 50)) {
		s.events="event3";
		s.prop3="SITETYPE";
		s.eVar3="evar3Value";
	
		s.Media.track(media.name);
		tracked50=true;
	}
	
	if ((!tracked60) && (media.percent >= 60)) {
			
		s.Media.track(media.name);
		tracked60=true;
	}
		
	if ((!tracked75) && (media.percent >= 75)) {
		s.events="event4";
		//Change value of prop1 one
		s.prop1="NEWLABLE/BUSINESS_UNIT";
		s.Media.track(media.name);
		tracked75=true;
	}
	
	
	if ((!tracked85) && (media.percent >= 85)) {
		s.events="event4";
		//Change value of prop1 one
		s.prop1="CHANGED LABLE/BUSINESS_UNIT";
		//Changed values being reported
		s.Media.trackVars="events,prop1,eVar1";
		s.Media.track(media.name);
		tracked85=true;
	}
	
	if(media.event=="CLOSE") {
		s.events="event5";
		s.Media.track(media.name);
	}
}

Open in new window

0
894359
Asked:
894359
1 Solution
 
H01Commented:
Hi 894359,

The error may cause by several issue:

1)  if you are trying to declare a variable name "s.dc" then base on your code AS3 will look for the variable name "dc" in component "s" that you import if it doesnt exits then it will prompt error. (Change the varaible name to something else then "s.dc")

2) if you are trying to declare a new variable name dc in component "s" then I dont think is possible.

3) if you are trying to set the variable "dc" which located in "s" component then the variable "dc" might not be a number type and you are assigning a number value to it. (you can try  s.dc = "112" )

0
 
894359Author Commented:
s.dc = "112" generates this error:

Implicit coercion of a value of type int to an unrelated type String

I can't change the name of the variable.
0
 
ariestavCommented:
You can't declare a variable (var) and use the dot syntax at the same time.  

You should try typecasting the value.  Have you tried:


s.dc = String(112);

The reason this may work is that it's not an implicit coercion.  It's definitely an explicit coercion.  Doesn't the error make you sound like a bad guy?  Coerce is such a bad word. . .

Let me know if that helps, or not . . .
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now